Java Program to Create a HashSet With Different Types of Items

You are currently viewing Java Program to Create a HashSet With Different Types of Items

Java program to create a HashSet with different types of items

// Java program to create a HashSet with 
// different types of items

import java.util.*;

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

    HashSet nums = new HashSet();

    nums.add("One");
    nums.add(2);
    nums.add(3.14);
    nums.add(true);

    System.out.println(nums);
  }
}

Output

[2, 3.14, One, true]

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