Share on Google+Share on Google+

Java hashset example.

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.


package net.roseindia;

import java.util.HashSet;

public class CreateHashSet {

public static void main(String[] arg) {

HashSet obHashSet = new HashSet();





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

 }  }

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


Posted on: April 4, 2011 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial 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.