Example of contains method of hashset in java.
Example of contains method of hashset in java.Code:
HashSetToArray .java
|
package net.roseindia;import java.util.HashSet;public class HashSetToArray { public static void main(String[] arg) {HashSet obHashSet = new HashSet();obHashSet.add( new Integer(1));obHashSet.add( new Integer(2));obHashSet.add( new Integer(3));obHashSet.add( new Integer(4));System. out.println("All Elements in HashSet : " + obHashSet); /*Check element is present or not in Hash set */ boolean b=obHashSet.contains(new Integer(3));System. out.println("Result : "+ b);} } |
|
All Elements in HashSet : [1, 2, 3, 4] Result : true |