Advertisement
Guest User

Untitled

a guest
Jul 11th, 2016
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.47 KB | None | 0 0
  1. import java.util.*;
  2.  
  3. class MyComp implements Comparator<String> {
  4.     public int compare(String a, String b) {
  5.         String a1, b1;
  6.         a1 = a;
  7.         b1 = b;    
  8.        
  9.         return b1.compareTo(a1);
  10.        
  11.     }
  12. }
  13. class CompDemo {
  14.     public static void main(String args[]) {
  15.         TreeSet<String> ts = new TreeSet<>(new MyComp());
  16.        
  17.         ts.add("a");
  18.         ts.add("f");
  19.         ts.add("y");
  20.         ts.add("t");
  21.         ts.add("w");
  22.         ts.add("z");
  23.         for(String el : ts) {
  24.             System.out.println(el + "  ");
  25.         }
  26.     }
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement