import java.util.LinkedList; public class Example { public static void main(String[] args) { LinkedListfruits = new LinkedList<>(); // Adding elements to the list fruits.add("Apple"); fruits.add("Banana"); fruits.add("Orange"); fruits.add("Grapes"); System.out.println(fruits); } }
[Apple, Banana, Orange, Grapes]
import java.util.LinkedList; public class Example { public static void main(String[] args) { LinkedListfruits = new LinkedList<>(); fruits.add("Apple"); fruits.add("Banana"); fruits.add("Grapes"); fruits.add(1, "Orange"); // add "Orange" at index 1 System.out.println(fruits); } }
[Apple, Orange, Banana, Grapes]The `java.util.LinkedList` class is part of the Java Standard Library, which is included in the `java.base` package.