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);} } |
| All data of HashSet : [Gyan, Ankita, Vrishti, Bharat] |
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.