+1 vote
in JAVA by

Explain about the different lists available in the collection.

Values added to the list is based on the index position and it is ordered by index position. Duplicates are allowed.

Types of Lists are:

Array List:

  • Fast iteration and fast Random Access.
  • It is an ordered collection (by index) and not sorted.
  • It implements Random Access Interface.

Example:

public class Fruits{
public static void main (String [ ] args){
ArrayList <String>names=new ArrayList <String>();
names.add (“apple”);
names.add (“cherry”);
names.add (“kiwi”);
names.add (“banana”);
names.add (“cherry”);
System.out.println (names);
}
}

Output:

[Apple, cherry, kiwi, banana, cherry]

From the output, Array List maintains the insertion order and it accepts the duplicates. But not sorted.

Vector:

It is same as Array List.

  • Vector methods are synchronized.
  • Thread safety.
  • It also implements the Random Access.
  • Thread safety usually causes a performance hit.

Related questions

+1 vote
asked Jun 16, 2019 in JAVA by reins.robin
+1 vote
asked May 24, 2019 in JAVA by rajeshsharma
...