I am trying to figure out how to increase array size... let say i created string array that can hold 7 names but the user wanted to enter more than 7... so i am trying to write a program that double my array size with out me changing it manualy ....
this is what i have so far...but it is not doubling my arry ...
public static void main(String[] args) throws IOException
{
System.out.println("please enter names");
BufferedReader read = new BufferedReader(new InputStreamReader(System.in));
String array[] = new String[7];
int count = 0;
for (int index = 0; index < array.length; index++ )
{
if( count == array.length)
{
String [] temp = new String[array.length * 2];
for ( int i = 0; i < array.length; i++)
{
temp[i] = array[i];
array = temp;
}
}
array[count] = read.readLine();
count++;
array[index] = read.readLine();
System.out.println("array["+index+"] = "+array[index]);
}
System.out.println( Arrays.toString(array) );
}
}