Java program to add an item into LinkedList collection on the specified index
// Java program to add an item into LinkedList collection
// on the specified index
import java.util.LinkedList;
public class Main {
public static void main(String[] args) {
LinkedList < String > countries = new LinkedList < String > ();
countries.add("India");
countries.add("USA");
countries.add("UK");
countries.add("CANADA");
System.out.println("Country names: " + countries);
countries.add(1, "CHINA");
System.out.println("Country names: " + countries);
}
}
Output
Country names: [India, USA, UK, CANADA]
Country names: [India, CHINA, USA, UK, CANADA]