We would like to know how to create a Set based on hash value.
import java.util.HashSet; import java.util.Set; /*from ww w. ja va 2 s . c o m*/ public class MainClass { public static void main(String[] a) { Set set = new HashSet(); set.add("Hello"); if (set.add("Hello")) { System.out.println("addition successful"); } else { System.out.println("addition failed"); } } }
The code above generates the following result.