Spread the love

List Concept Simplified In Java

Spread the love

List Concept Simplified In Java
List Concept Simplified In Java
What is a List:

The list concept is the child interface of collection. Collection interface was introduced in java 1.2 version and  List Interface got introduced in the same version. The List interface contains an ordered sequence of elements available in a collection. It allows duplicate elements in the list. The List interface inherits the methods of Collection interface.

Inside the list interface, there are 3 primary classes. They are…

  1. ArrayList-1.2 version
  2. AbstractSequentialList-1.2 Version
  3. Vector-1.0 version (Legacy class)

2.1 LinkedList-1.2 Version
3.1 Stack (1.0 version-legacy class)

When we should use a list:

If we want to represent a group of individual objects as a single entity where duplicates are allowed and insertion order preserved then we should go for List interface.
In Java 1.2 version Vector, Stack classes are re-engineered to implement List interface.

As we can preserve the insertion order hence index will be generated. We can differentiate duplicate objects by using Index. So Index plays an important role in List.

List concept Interface is having the following methods:

void add(int index,Object o);//adds the element 'o' in the specified index.
void add(int index,Collection c);//adds the elements of the collection c at the specified index.
boolean addAll(int index,Collection c);//adds the elements of the collection c at the specified index.
Object get(int index);//returns the element available in the specified index.
Object remove(int index);//removes the element available in the specified index.
Object set(int index,Object new);//This method is very interesting, it replaces the element present at
// specified index with provided object and returns old object]
int indexOf(Object o); //returns the index of first occurrence of o,if it does not available it returns -1
int lastIndexOf(Object o);//returns the index of last occurrence of o,if it does not available it returns -1
ListIterator listIterator();//returns a listIterator of the elements
ListIterator listIterator(int index);//returns a listIterator of the elements from the specified index.
void set(int index,Object o);//replaces the element in the specified index with specified element.
List subList(int stratIndex,int endIndex);//returns the elements available from the specified boundaries.

READ  All About Class BitSet in Java
READ  Vector Class Simplified in Java




Spread the love
Animesh Chatterjeehttps://techtravelhub.com/
I am the founder and owner of the blog - TechTravelHub.com, always love to share knowledge on test automation,tools,techniques and tips.I am a passionate coder of Java and VBScript.I also publish articles on Travel ideas and great honeymoon destinations.Apart from these, I am a gear-head,love to drive across India. I have shared lots of articles here on How to travel several parts of India.Customization of cars aka car modification is my another hobby.Get in touch with me on ani01104@gamil.com

Related Articles

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special keyword called...

Comments

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Recent Posts

Super Keyword in Java Simplified

Super Keyword Super Keyword in Java Simplified: Java defines a special...

Learn Object Repository in UFT in An Efficient and Fast Manner

Object Repository in UFT The post will cover the following...

Learn What Primary Tools For Test Automation

Primary Tools For Test Automation According to the Gartner report...

EDITOR PICKS


Spread the love