I'm using ArrayList<String>
and I add data at specific indices, how can I check if a specific index exists?
Should I simply get()
and check the value? Or should I wait for an exception?
Is there another way?
Update: Thank you for your answers, but because I'm only adding stuff at specific indices, the length of the list will not show me which are available.
get()
and check fornull
- don't rely on exceptions though. Consider using aHashTable
instead java.sun.com/j2se/1.4.2/docs/api/java/util/Hashtable.html