What is list?
List in an interface, which is implemented by the ArrayList, LinkedList, Vector and Stack. It is an ordered collection of the object, where duplicate objects can also be stored.
In this example, we are performing following operations:
- Creating a list of integers - implemented by ArrayList
- Printing the empty List
- Adding elements to the List and printing
- Adding elements to the List at given indexes and printing
- Removing elements from the List by index and printing
Following methods are using in the program:
- List.add(element) - Adds element at the end of the List
- List.add(index, element) - Inserts element at given index
- List.remove(index) - Removes the element from given index
-
Example:
Output