what is linkedlist in java code example

Example 1: how to declare a linked list in java

LinkedList<String> list=new LinkedList<String>();

Example 2: linkedlist in java

LinkedList not synchronized, doubly linked

Example 3: linked list in java

// Java program to iterate the elements  
// in an LinkedList 
    
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");  
    
        // Using the Get method and the  
        // for loop  
        for (int i = 0; i < ll.size(); i++) {  
    
            System.out.print(ll.get(i) + " ");  
        }  
    
        System.out.println();  
    
        // Using the for each loop  
        for (String str : ll)  
            System.out.print(str + " ");  
    }  
}

Tags:

Java Example