Tag: ArrayList

Accessing ArrayList Elements

To access a single ArrayList element, use ArrayList.get() method. To print all elements, you can use a simple for loop with ArrayList.get() method or use an Iterator object to iterate…

ArrayList NullPointerException

Java’s ArrayList is a great Collection that frees us from IndexOutOfBound, one type limitation, and NullPointerException issues while providing several value-added methods. Naturally, you would be shocked if you encounter…

ArrayList and Iterator Example

This example shows how to use an iterator with ArrayList. Iterator can be used with other collections. output Note that if you are using Java 5 or above, you will…