List in Java
 (1).png)
imports
Array List
Array List 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).
Creating a List
If you try to add something to the lists above you will get a NullPointerException
, because strings and doubles, both equal null!
Positional Access Operations
add(T type)
add(int index, T type)
remove(Object o)
remove(int index)
get(int index)
set(int index, E element)
int indexOf(Object o)
int lastIndexOf(Object o)
Iterating over the List
To add an element
myArrayList.add(element);
myArrayList.add(index, element);
//index of the element should be an int (starting from 0)
To remove
myArrayList.remove(element);
myArrayList.remove(index);
//index of the element should be an int (starting from 0)
- Removing elements from list B that are present in the list A