Lists

suggest change

Introduction

A list is an ordered collection of values. In Java, lists are part of the Java Collections Framework. Lists implement the java.util.List interface, which extends java.util.Collection.

Syntax

Remarks

A list is an object which stores a an ordered collection of values. “Ordered” means the values are stored in a particular order–one item comes first, one comes second, and so on. The individual values are commonly called “elements”. Java lists typically provide these features:

Adding a value to a list at some point other than the end will move all of the following elements “down” or “to the right”. In other words, adding an element at index n moves the element which used to be at index n to index n+1, and so on. For example:

List<String> list = new ArrayList<>();
list.add("world");
System.out.println(list.indexOf("world"));      // Prints "0"
// Inserting a new value at index 0 moves "world" to index 1
list.add(0, "Hello");
System.out.println(list.indexOf("world"));      // Prints "1"
System.out.println(list.indexOf("Hello"));      // Prints "0"

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:


Lists:
* Lists

Table Of Contents
8 Arrays
10 Maps
11 Strings
25 JAXB
29 Enums
32 Audio
41 Scanner
63 Logging
75 Lists
78 Sets
89 JAX-WS
96 XJC
98 Process
106 Modules
114 Applets
122 JNDI
139 JavaBean
141 Literals
144 Packages
150 JMX
153 JShell
159 Sockets
167 Enum Map
175 Hashtable
177 SortedMap