I am writing a sample code to accept as many integer inputs as user provides and store them in vector list and then copy the items of the vector to int array but it shows syntax error in array[a]=list.elementAt(a);
import java.util.Vector;
import java.io.*;
public class HelloWorld{
public static void main(String []args)throws IOException{
BufferedReader in=new BufferedReader(new InputStreamReader(System.in));
Vector list =new Vector();
while(true)
{
String s=in.readLine();
if(s.equals(""))
break;
int i=Integer.parseInt(s);
Integer item=i;//autoboxing initialization of Integer object
list.addElement(item); //adding to the list till user gives input
}
int array[]=new int[(int)list.size()];
for(int a=0;a<array.length;a++)
array[a]=list.elementAt(a);//Error is show here
System.out.print(java.util.Arrays.toString(array));
}
}
If you have any other way to do this then please do share.