Creating Adding and Removing element from an ArrayList

suggest change

ArrayList is one of the inbuilt data structures in Java. It is a dynamic array (where the size of the data structure not needed to be declared first) for storing elements (Objects).

It extends AbstractList class and implements List interface. An ArrayList can contain duplicate elements where it maintains insertion order. It should be noted that the class ArrayList is non-synchronized, so care should be taken when handling concurrency with ArrayList. ArrayList allows random access because array works at the index basis. Manipulation is slow in ArrayList because of shifting that often occurs when an element is removed from the array list.

An ArrayList can be created as follows:

List<T> myArrayList = new ArrayList<>();

Where T ( http://stackoverflow.com/documentation/java/92/generics#t=201607261408489085381 ) is the type that will be stored inside ArrayList.

The type of the ArrayList can be any Object. The type can’t be a primitive type (use their wrapper classes instead).

To add an element to the ArrayList, use add() method:

myArrayList.add(element);

Or to add item to a certain index:

myArrayList.add(index, element); //index of the element should be an int (starting from 0)

To remove an item from the ArrayList, use the remove() method:

myArrayList.remove(element);

Or to remove an item from a certain index:

myArrayList.remove(index); //index of the element should be an int (starting from 0)

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Lists:
* Lists
* Creating Adding and Removing element from an ArrayList

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap