List Interface:
List allows Duplicate Elements.
List having index.
List allows n number of null values.
List will display Insertion order with index.
List having classes like :
Vector
ArrayList
LinkedList
Vector:
Vector is a legacy class.
Vector is synchronized.
Vector initial capacity is 10.
Vector allows n number of null values
Vector can be accessible by index.
Vector allows Duplicate Elements.
Program for Vector:
package com.instanceofjavaforus;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
public class A{
public static void main(String[] args) {
Vector vector=new Vector();
vector.add("india");
vector.add("jagan");
vector.add("sam");
vector.addElement(null);
vector.addElement(null);
Enumeration em=vector.elements();
while(em.hasMoreElements()){
System.out.println(em.nextElement());
}
}
}
Output:
india
jagan
sam
null
null
ArrayList:
ArrayList is not Synchronized.
Arraylist also allows Duplicate Elements.
ArrayList allows n number of null values.
Arraylist having insertion order with index.
For retrieve purpose ArrayList is best choice.
ArrayList having Randaom Access Nature.
Program for ArrayList ;
package com.instanceofjava;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.List;
public class A{
public static void main(String[] args) {
ArrayList arrayList=new ArrayList();
arrayList.add("jagan");
arrayList.add("jagan");
arrayList.add("upendra");
arrayList.add(null);
arrayList.add(null);
ListIterator it=arrayList.listIterator();
while(it.hasNext()){
System.out.println(it.hasNext());
}
}
}
Output:
jagan
jagan
upendra
null
null
LinkedList:
LinkedList is not synchronized.
LinkedList allows n number of null values.
LinkedList allows Duplicate Elements.
LinkedList having insertion order with index.
Insertion and Deletion purpose LinkedList is better choice.
LinkedList Follows Doubly linked list Structure.
Program for LinkedList:
package com.instanceofjava;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.List;
public class A{
public static void main(String[] args) {
LinkedList linkedList=new LinkedList();
linkedList.add("jagan");
linkedList.add("jagan");
linkedList.add("naresh");
linkedList.add(null);
linkedList.add(null);
ListIterator it=linkedList.listIterator();
while(it.hasNext()){
System.out.println(it.hasNext());
}
}
}
Output:
jagan
jagan
naresh
null
null
In List interface if you want to add elements we can use add() method.
If you want to remove elements we can use remove() method.
List allows Duplicate Elements.
List having index.
List allows n number of null values.
List will display Insertion order with index.
List having classes like :
Vector
ArrayList
LinkedList
Vector:
Vector is a legacy class.
Vector is synchronized.
Vector initial capacity is 10.
Vector allows n number of null values
Vector can be accessible by index.
Vector allows Duplicate Elements.
Program for Vector:
package com.instanceofjavaforus;
import java.util.Enumeration;
import java.util.List;
import java.util.Vector;
public class A{
public static void main(String[] args) {
Vector vector=new Vector();
vector.add("india");
vector.add("jagan");
vector.add("sam");
vector.addElement(null);
vector.addElement(null);
Enumeration em=vector.elements();
while(em.hasMoreElements()){
System.out.println(em.nextElement());
}
}
}
Output:
india
jagan
sam
null
null
ArrayList:
ArrayList is not Synchronized.
Arraylist also allows Duplicate Elements.
ArrayList allows n number of null values.
Arraylist having insertion order with index.
For retrieve purpose ArrayList is best choice.
ArrayList having Randaom Access Nature.
Program for ArrayList ;
package com.instanceofjava;
import java.util.ArrayList;
import java.util.ListIterator;
import java.util.List;
public class A{
public static void main(String[] args) {
ArrayList arrayList=new ArrayList();
arrayList.add("jagan");
arrayList.add("jagan");
arrayList.add("upendra");
arrayList.add(null);
arrayList.add(null);
ListIterator it=arrayList.listIterator();
while(it.hasNext()){
System.out.println(it.hasNext());
}
}
}
Output:
jagan
jagan
upendra
null
null
LinkedList:
LinkedList is not synchronized.
LinkedList allows n number of null values.
LinkedList allows Duplicate Elements.
LinkedList having insertion order with index.
Insertion and Deletion purpose LinkedList is better choice.
LinkedList Follows Doubly linked list Structure.
Program for LinkedList:
package com.instanceofjava;
import java.util.LinkedList;
import java.util.ListIterator;
import java.util.List;
public class A{
public static void main(String[] args) {
LinkedList linkedList=new LinkedList();
linkedList.add("jagan");
linkedList.add("jagan");
linkedList.add("naresh");
linkedList.add(null);
linkedList.add(null);
ListIterator it=linkedList.listIterator();
while(it.hasNext()){
System.out.println(it.hasNext());
}
}
}
Output:
jagan
jagan
naresh
null
null
In List interface if you want to add elements we can use add() method.
If you want to remove elements we can use remove() method.
No comments:
Post a Comment