java2db

What is List interface in java



The List interface is a sub interface of Collection under java.util package . it’s index stars from zero (0) . The diagram represents, List interface and it’s implementations .

 

List interface List is an ordered collection , it allows both duplicates and null elements .

List interface we can search elements by index .

List interface It is not a synchronized collection , Use Collections.synchronizedList(List list)for synchronized List .

 

 

 

All methods of List interface :

 

Syntax:

List ‹generic type› ‹object name›= new <List implemented class name>‹generic type›(); or

Example for List interface :

 

Few more methods :

Method Name Returns Description
addAll(Collection) Boolean To add Collection of elements ( if they are not present).
containsAll(Collection) Boolean Returns true , if the List having all elements.
iterator() Iterator To iterate  List .
removeAll(Collection) boolean To Remove specified Collection of elements .
retainAll(Collection) boolean To Keep specified Collection of elements  .
toArray() Object[] It returns an array with all elements .
toArray(T[] t) T[] It returns specified array(ex:String[]) ,with all elements  .
listIterator() ListIterator To iterate List .

List interfaceSome of the List implementations prohibits to add null elements .




Related Posts :
What is an interface and how to work with an interface in java
What is the difference between interface and abstract class in java
What is Map interface in java
What is Set interface in java
Difference between List and Set
   [will not be published]



^ <