React.js
Angular
Ethical Hacking
Agile
AWS
BlockChain
Cassandra
Cloud
Salesforce
Scaled Agile
TOGAF
DevOps
GIT
Jenkins
Jira
Kibana
Linux
NGINX
Ansible
Artificial Intelligence
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.
Click here to read more about DevOps

Related questions

Madanswer
0 votes
asked May 24, 2019 in JAVA by rajeshsharma
0 votes
asked May 24, 2019 in JAVA by rajeshsharma
...