Add and display the elements(4 elements) using HashSet, check if an element exists there in a hashset,remove the element..
Find the smallest and largest element(number) using treeset
class Display
{
public static void main(String args[])
{
HashSet<String> a=new HashSet<String>();
a.add(“apple”);
a.add(“mango”);
a.add(“banana”);
a.add(“apple”); //apple mango banana
System.out.println(“mango is there..”+a.contains(“mango”));
a.remove(“mango”);
System.out.println(a);
}
}
—————————————————–
import java.util.*;
class ASC
{
public static void main(String args[])
{
TreeSet<Integer> a=new TreeSet<Integer>();
a.add(50);
a.add(20);
a.add(50);
a.add(40); //20 40 50
System.out.println(“Smallest=”+a.first());
System.out.println(“Largest=”+a.last());
}
}