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

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -