The important points about Java Linked List are:
- Java Linked List class can contain duplicate elements.
- Java Linked List class maintains insertion order.
- Java Linked List class is non synchronized.
- In Java Linked List class, manipulation is fast because no shifting needs to be occurred.
- Java Linked List class can be used as list, stack or queue. Syntax:- Link List<string>name=new Linked List<string>(); {
Public Class MyClass
{
pulic static void main(string[] args)
{
LinkList<string>name=new LinkedList<string>();
name.add(“ABC”); //Add a name in LinkList
name.add(“PQR”); //Add a name in LinkList
name.add(“XYZ”); //Add a name in LinkList
for(string:name)
System.out.println(x);
name.addfirst(“Jack”); //Add First name in LinkList.
name.addlast(“Zack”); //Add Last name in LinkList.
name.removelast(); //Remove First name in LinkList.
name.removefirst(); // Remove Last name in LinkList.
name.clear(); //Delete all the data in LinkList.
System.out.println(name.size());
name.add(index,”element”); //This is a syntax for add a variable of particular position in LinkList.
name.add(2,”Index”);
name.remove(2); // Remove a variable of particular position in LinkList
name.set(1,”a”); //Change a name as particular index.
}
}