Java Program to Get the Items From LinkedList Collection Using the Index

You are currently viewing Java Program to Get the Items From LinkedList Collection Using the Index

Java program to get the items from LinkedList collection using the index

// Java program to get the items from LinkedList collection
// using the 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: ");
    for (int i = 0; i < 4; i++) {
      System.out.println(countries.get(i));
    }
  }
}

Output

Country names: 
India
USA
UK
CANADA

Ranjith

Hi, I'm Manoj a full-time Blogger, YouTuber, Affiliate Marketer, & founder of Coding Diksha. Here, I post about programming to help developers.

Leave a Reply