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
views:
94answers:
4
+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
2010-08-30 15:00:18
Thanks mohammad
sivaraj
2010-08-31 10:01:06
+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
2010-08-30 15:00:18
+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
2010-08-30 15:11:39