What are Lists in java?

List is the child interface of Collection. It is a part of the Collection framework. List is an ordered collection of objects in which duplicate values can be stored. Since List is an interface, we need to use the implementation class to create an object. We will be using the ArrayList class for this purpose. The way to create an object for a List is shown here:

List simpleList = new ArrayList(); or

List<String> simpleList = new ArrayList<String>();

The second listing contains generics. Here, we specify that our List is going to contain only strings, whereas the first version specifies that our list will contain any kind of object.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.222.162.216