how to initialize a dynamic array in java?
Answers
Answered by
0
n=10;
int a [ ]=new int [n];
Now you got
Answered by
2
Java has built-in dynamic arrays like Vector, ArrayList, LinkedList and CopyOnWriteArrayList.
For most cases ArrayList satisfies our needs, so,
We can initialize a ArrayList by,
ArrayList<Type> object_name = new ArrayList<Type>( ); or,
ArrayList<Type> object_name = new ArrayList<Type>(
Arrays.asList(Object obj1, Object obj2, Object obj3, ....));
Similar questions