java - How to get size() of initialized ArrayList? -
i have code similar this:
arraylist<sometype> togetsizeof = new arraylist<sometype>(); int size = togetsizeof.size(); however, second line giving me nullpointerexception. there way avoid this, tell if arraylist has been initialized has not of yet had added yet? (i have if/else statement dependent on this).
thanks in advance!
i think perhaps else wrong in code.
the following works fine:
arraylist<string> togetsizeof = new arraylist<string>(); int size = togetsizeof.size(); system.out.println(size); which gives 0.
debug code , check null. suspect it's togetsizeof.
Comments
Post a Comment