Home Tutorial Java Core Hashset Java hashset example.

 
 

Share on Google+Share on Google+
Java hashset example.
Posted on: April 4, 2011 at 12:00 AM
Advertisement
Java hashset example.

Java hashset example.

    HashSet is a collection. You can not store duplicate value in HashSet.

In this java hashset exmple, you will see how to create HashSet in java application and how to store value in Hashset. There is  a method called add, it is used to store value in it.

Code

CreateHashSet.java

package net.roseindia;

import java.util.HashSet;

public class CreateHashSet {

public static void main(String[] arg) {

HashSet obHashSet = new HashSet();

obHashSet.add("Bharat");

obHashSet.add("Gyan");

obHashSet.add("Ankita");

obHashSet.add("Vrishti");

System.out.println("All data of HashSet : " + obHashSet);

 }  }

Output :
All data of HashSet : [Gyan, Ankita, Vrishti, Bharat]
Advertisement

Related Tags for Java hashset example.:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: April 4, 2011

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com