package corejava; import java.util.*; public class SetExample { public static void main(String args[]) { int count[] = { 3, 12, 21, 30, 48, 84 }; Set set = new HashSet(); try { for (int i = 0; i < 3; i++) { set.add(count[i]); } System.out.println(set); TreeSet sortedSet = new TreeSet(set); System.out.println("The sorted list is:"); System.out.println(sortedSet); System.out.println("First element in the set: " + (Integer) sortedSet.first()); System.out.println("Last element in the set: " + (Integer) sortedSet.last()); } catch (Exception e) { } } }