Java Program to Create a HashSet With String Items

Java program to create a HashSet with string items

// Java program to create a HashSet 
// with string items

import java.util.*;

public class Main {
  public static void main(String[] args) {

    HashSet < String > cities = new HashSet();

    cities.add("MUMBAI");
    cities.add("NEW-DELHI");
    cities.add("AGRA");
    cities.add("INDORE");

    System.out.println("Cities are: \n" + cities);
  }
}

Output

Cities are: 
[MUMBAI, AGRA, NEW-DELHI, INDORE]
Share on:

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

Leave a Comment