fork(1) download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7.  
  8. class M{
  9. public int age;
  10. public M(int n) { age = n; }
  11. public String toString() { return String.valueOf(age); }
  12. }
  13.  
  14. /* Name of the class has to be "Main" only if the class is public. */
  15. class Ideone
  16. {
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. // your code goes here
  20. TreeSet st =new TreeSet((o1,o2)->((M)o2).age-((M)o1).age);
  21. st.add(new M(10));
  22. st.add(new M(5));
  23. st.add(new M(2));
  24. st.add(new M(7));
  25. st.add(new M(11));
  26. st.add(new M(3));
  27. for (Object m: st)
  28. System.out.println((M)m);
  29. }
  30. }
Success #stdin #stdout 0.21s 33404KB
stdin
Standard input is empty
stdout
11
10
7
5
3
2