Design a site like this with WordPress.com
Get started

List

A List is data structure where objects are stored in insertion order, It means that the objects inserted into a list maintain its position in the collection. So a list can be defined as collection of objects where objects are stored in the insertion order.

With a list implementation, it is possible to add/remove/set an object using the index.

E.g. Consider below representation of list

The Objects in the list can be accessed using their indices. so, if I want to fetch banana which is at the second position in the list, I can just fetch it from the list using the index number “list.get(2)”. As said earlier, the position is maintained in a list implementations, so the banana was the third object in the list at the time of insertion, will be the same at the time of extraction.

Here the important thing to note in any list implementaion is that all list’s maintain order of insertion.

In Java, there are primarily 2 types of list implementation
1) ArrayList 2) LinkedList

Both the above collections have their own usage purposes, I will talk about it in the next tutorial.

Please take a look at the list interface in the java sources to have a better understanding.



Advertisement

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: