Question: /****** * Q3: [15 marks] * create Q3 class to implement comparator for a TreeSet. The purpose of * the comparator is to compare the

/****** * Q3: [15 marks] * create Q3 class to implement comparator for a TreeSet. The purpose of * the comparator is to compare the alphabetic order of integers. With 13, * the order of Integer elements will be sort according to the order of * digit Unicode. * For example, the value of {11,3,31,2} will return {11,2,3,31} * NOTE: You don't need to compare each digit one by one. Just compare them as strings. **** *****/ System.out.println("Q3 - [15 marks] "); Set Integer set = new TreeSet(new Q3(); Integer[] arr3 = {11,3,31,2}; set.addAll(Arrays.asList(arr3)); for (Integer element: set) System.out.print(element+"\t"); System.out.println(); class Q3 implements Comparator
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
