How to create Hashset In Java

import java.util.HashSet;
import java.util.Set;

public class CreateHashset {

public static void main(String[] args) {

Set<String> hs = new HashSet<String>();

hs.add(“java”);
hs.add(“php”);
hs.add(“html”);
hs.add(“javascript”);
hs.add(“vb”);

//print hashset
System.out.println(“hashset = “+hs);

}
}

Output:

hashset = [javascript, php, html, java, vb]

Leave a Reply

Your email address will not be published. Required fields are marked *

28 + = 32