Java Program to Remove All Items From LinkedList Collection

You are currently viewing Java Program to Remove All Items From LinkedList Collection

Java program to remove all items from LinkedList collection

// Java program to remove all items from 
// LinkedList collection

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.clear();

    System.out.println("Country names: " + countries);
  }
}

Output

Country names: [India, USA, UK, CANADA]
Country names: []

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