Opening Hours :7AM to 9PM
LinkedList<wrapperclass> objref=new LinkedList<wrapperclass>();Linkedlist contains following methods.
import java.util.*; class LinkedListAdd { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); al.add(50); System.out.println("The List Items Are "+al); } } class Main { public static void main(String args[]) { LinkedListAdd d=new LinkedListAdd(); d.list(); } }
import java.util.*; class LinkedListAddFirst { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); al.addFirst(500); System.out.println("The List Items Are "+al); } } class Main { public static void main(String args[]) { LinkedListAddFirst d=new LinkedListAddFirst(); d.list(); } }
import java.util.*; class LinkedListAddIndex { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); al.add(1,1000); System.out.println(al); } } class Main { public static void main(String args[]) { LinkedListAddIndex d=new LinkedListAddIndex(); d.list(); } }
class LinkedListAddLast { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.addLast(500); al.add(30); al.add(40); System.out.println("The List Items Are "+al); } } class Main { public static void main(String args[]) { LinkedListAddLast d=new LinkedListAddLast(); d.list(); } }Note: by default add method access the last method.
import java.util.*; class LinkedListClear { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); al.clear(); System.out.println(al); } } class Main { public static void main(String args[]) { LinkedListClear d=new LinkedListClear(); d.list(); } }
import java.util.*; class LinkedListGetFirst { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); System.out.println("The First Item is "+al.getFirst()); } } class Main { public static void main(String args[]) { LinkedListGetFirst d=new LinkedListGetFirst(); d.list(); } }
import java.util.*; class LinkedListGetIndex { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); System.out.println(al.get(3)); } } class Main { public static void main(String args[]) { LinkedListGetIndex d=new LinkedListGetIndex(); d.list(); } }
import java.util.*; class LinkedListGetLast { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); System.out.println("The Last Item is "+al.getLast()); } } class Main { public static void main(String args[]) { LinkedListGetLast d=new LinkedListGetLast(); d.list(); } }
import java.util.*; class LinkedListRemoveFirst { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); al.removeFirst(); System.out.println(al); } } class Main { public static void main(String args[]) { LinkedListRemoveFirst d=new LinkedListRemoveFirst(); d.list(); } }
import java.util.*; class LinkedListRemoveIndex { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); al.remove(1); System.out.println(al); } } class Main { public static void main(String args[]) { LinkedListRemoveIndex d=new LinkedListRemoveIndex(); d.list(); } }
import java.util.*; class LinkedListRemoveLast { void list() { LinkedList<Integer> al=new LinkedList<Integer>(); al.add(20); al.add(10); al.add(30); al.add(40); System.out.println("The List Items Are "+al); al.removeLast(); System.out.println(al); } } class Main { public static void main(String args[]) { LinkedListRemoveLast d=new LinkedListRemoveLast(); d.list(); } }