fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. List<Test> tests = new ArrayList<Test>();
  13. tests.add(new Test("C1"));
  14. tests.add(new Test("C2"));
  15. tests.add(new Test("C1"));
  16. tests.add(new Test("C2"));
  17.  
  18. Collections.sort(tests, new Comparator<Test>() {
  19. public int compare(Test test1, Test test2){
  20. return test1.description.compareTo(test2.description) * -1;
  21. }
  22. });
  23.  
  24. for(Test test: tests)
  25. {
  26. System.out.println(test.description);
  27. }
  28. }
  29. }
  30.  
  31. class Test
  32. {
  33. public String description;
  34.  
  35.  
  36. public Test(String description)
  37. {
  38. this.description = description;
  39. }
  40. }
Success #stdin #stdout 0.08s 381184KB
stdin
Standard input is empty
stdout
C2
C2
C1
C1