linked list object java code example
Example 1: java linked list functions
import java.util.LinkedList;
LinkedList<Integer> myList = new LinkedList<Integer>();
myList.add(0);
myList.remove(0);
myList.size();
myList.get(0);
Example 2: linked list in java
import java.util.*;
public class GFG {
public static void main(String args[])
{
LinkedList<String> ll
= new LinkedList<>();
ll.add("Geeks");
ll.add("Geeks");
ll.add(1, "For");
for (int i = 0; i < ll.size(); i++) {
System.out.print(ll.get(i) + " ");
}
System.out.println();
for (String str : ll)
System.out.print(str + " ");
}
}