1 package start; 2 3 import java.awt.List; 4 import java.util.LinkedList; 5 6 public class Linkedlist { 7 8 public static void main(String[] args) { 9 // Create a LinkedList 10 LinkedList<Integer> list = new LinkedList<Integer>(); 11 12 // Add element 13 // Time Complexity: O(1) 14 list.add(1); 15 list.add(2); 16 list.add(3); 17 // [1,2,3] 18 System.out.println(list.toString()); 19 20 // Insert element 21 // Time Complexity: O(N) 22 list.add(2, 99); 23 // [1,2,99,3] 24 System.out.println(list.toString()); 25 26 // Access Element 27 // Time Complexity: O(N) 28 int element = list.get(2); 29 // 99 30 System.out.println(element); 31 32 // Search element 33 // Time Complexity:O(N) 34 int index = list.indexOf(99); 35 // 2 36 System.out.println(index); 37 38 // Update element 39 // Time Complexity: O(N) 40 list.set(2, 88); 41 //[1,2,88,3] 42 System.out.println(list.toString()); 43 44 //Remove element 45 //Time Complexity: O(N) 46 list.remove(2); 47 System.out.println(list.toString()); 48 49 // length 50 //Time Complexity:O(1) 51 int length=list.size(); 52 System.out.println(length); 53 } 54 55 }