Learnerslesson
   JAVA   
  SPRING  
  SPRINGBOOT  
 HIBERNATE 
  HADOOP  
   HIVE   
   ALGORITHMS   
   PYTHON   
   GO   
   KOTLIN   
   C#   
   RUBY   
   C++   




Java - List

List interface is also an implementation of Collections interface which is needed if we want duplicate entries. In other words List will allow duplicate elements to be added in it.

The concrete implementations of List are:


java_List

Methods used in List

Note : We will be explaining the below methods in detail, when we start explaining the concrete implementation of List (i.e. ArrayList and LinkedList)


  1. void add(Object obj)

It is used to add an element at the end of the 'List' .


  1. void add(int index,Object obj)

It is used to insert an element into the 'List' at a particular position mentioned in the index.

i.e. If you want to add an element/Object at the 3rd position of the existing List. This method helps you to achieve that.


  1. boolean addAll(int index,Collection collection)

It is used to add all elements of 'Collection' into the 'List' at a particular position mentioned in the index.



  1. Object get(int index)

It is used to return an object stored at a particular location mentioned in the index.

i.e. Say if you want to store in Object/element at the 3rd position of the List. This method comes handy in that case.


  1. object set(int index,Object obj)

It is used to replace an element at a particular location mentioned in the index.


  1. object remove(int index)

It is used to delete an element at a particular location mentioned in the index and return the deleted element.


  1. ListIterator listIterator()

It is used to Iterate the elements in the List. Say, you have 10 elements in a List and want to iterate them one by one. listIterator() helps you to achieve that.


  1. ListIterator listIterator(int index)

It is also used to Iterate the elements in the List but from a specific position mentioned in the 'index'.

i.e.Say, you have 10 elements in a List and want to iterate them starting from the 5th one. You can achieve that using this method.


Note : All the above methods will be used in the concrete implementation of List (i.e. In ArrayList and LinkedList).




</