tags:

views:

94

answers:

4

I am using String Array declare as zoom z[]=new String[422];but this array store value from 0 to 32,so i got null pointer exception after looping value 32,how to solve this problem in java,How can i declare dynamic array in java

+1  A: 

no, there is no way to make array length dynamic in java. you can use ArrayList or other List implementations instead.

mohammad shamsi
Thanks mohammad
sivaraj
+3  A: 

You want to use a Set or List implementation (e.g. HashSet, TreeSet, etc, or ArrayList, LinkedList, etc..), since Java does not have dynamically sized arrays.

List zoom = new ArrayList<String>();
zoom.add("String 1");
zoom.add("String 2");

for (String z : zoom) {
    System.err.println(z);
}
Chadwick
thanks chadwick
sivaraj
+1  A: 

Maybe you are looking for Vector. It's capacity is automatically expanded if needed. It's not the best choice but will do in simple situations. It's worth your time to read up on ArrayList instead.

Kelly French
Thanks kelly,i am using array list in app
sivaraj
A: 

we can use Array List..

sivaraj