java.util.hashset code example
Example 1: java hashset
HashSet<String> hset = new HashSet<String>();
hset.add("Apple");
hset.add("Mango");
Example 2: hashset in java
import java.util.HashMap;
public class HashMapExample
{
public static void main(String[] args)
{
HashMap<Integer, String> hm = new HashMap<Integer, String>();
hm.put(10,"Apple");
hm.put(20,"Banana");
hm.put(30,"Cherry");
hm.put(40,"Dragonfruit");
System.out.println("HashMap elements: " + hm);
}
}
Example 3: hashset in java
- HashSet can have null, order is not guaranteed