Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.util.*;
- class MyComp implements Comparator<String> {
- public int compare(String a, String b) {
- String a1, b1;
- a1 = a;
- b1 = b;
- return b1.compareTo(a1);
- }
- }
- class CompDemo {
- public static void main(String args[]) {
- TreeSet<String> ts = new TreeSet<>(new MyComp());
- ts.add("a");
- ts.add("f");
- ts.add("y");
- ts.add("t");
- ts.add("w");
- ts.add("z");
- for(String el : ts) {
- System.out.println(el + " ");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement