Stack
Stack is also concrete class which provides the implementation of List interface.
Example
import java.util.Stack;
public class StackDemo {
public static void main(String[] args) {
Stack s = new Stack();
s.push("one");
s.push("two");
s.push("three");
s.push("Four");
s.push("five");
System.out.println(s);
s.pop();
System.out.println(s);
System.out.println(s.peek());
}
}
Try it »
Linked List
- It’s also concrete class which providing the implementation of list interface and object of this class is responsible to Create doubly linked list in memory.
- Apart from doubly linked list this class is also provide the implementation of stack and Queue.
Commonly used constructor in Linked List
- public LinkedList()
- public LinkedList(Collection c)
Example
ipackage com.collection.programs;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
public class LinkedList {
public static void main(String[] args) {
// TODO Auto-generated method stub
java.util.LinkedList list = new java.util.LinkedList();
list.add(10);
list.add(1);
list.add(12);
list.add(4);
list.add(8);
System.out.println("Add Element into the linked list");
System.out.println(list);
System.out.println("Create a new linked list and pass the another list");
java.util.LinkedList list1 = new java.util.LinkedList(list);
list.add(14);
list.add(18);
System.out.println(list);
}
}
Try it »