HashSet in Java
import [Link];
import [Link];
public class Hashing {
public static void main(String args[]) {
HashSet<Integer> set = new HashSet<>();
//Add
[Link](1);
[Link](2);
[Link](3);
[Link](1);
//Size
[Link]("size of set is : " + [Link]());
//Search
if([Link](1)) {
[Link]("present");
}
if() {
[Link]("absent");
}
//Delete
[Link](1);
if() {
[Link]("absent");
}
//Print all elements
[Link](set);
//Iteration - HashSet does not have an order
[Link](0);
Iterator it = [Link]();
while ([Link]()) {
[Link]([Link]() + ", ");
}
[Link]();
//isEmpty
if(![Link]()) {
[Link]("set is not empty");
}
}
}