ArrayList and iterator

An ArrayList and an array are closely related.
A big difference to the usual array is that when creating an ArrayList, no size has to be specified. The size of an ArrayList adjusts dynamically.

As with the array, when creating an ArrayList, you have the option of specifying only the data type of the values, without making an assignment of values.

For the assignment of values, the ArrayList provides you with the add() method. The ArrayList also provides a method for removing values, the remove() method.

Syntax ArrayList

ArrayList <Type> listname = new ArrayList <Type>();

// add element

// remove element

Syntax Iterator

An iterator allows sequential access to the elements of a collection – for example, an ArrayList.

Iterator<Type> iter = arraylist_name.iterator();