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. /* 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. Test[] testArray = new Test[] {
  13. new Test(1385105640000L),
  14. new Test(1376712950000L),
  15. new Test(1385191974000L),
  16. new Test(1385172503000L) };
  17.  
  18. List<Test> testList = new ArrayList<Test>(Arrays.asList(testArray));
  19.  
  20. Collections.sort(testList, testDesc);
  21.  
  22. for (Test t: testList)
  23. System.out.println(t.toString());
  24.  
  25.  
  26. /* Resolução Correta:
  27. * Test [time=1385191974000L]
  28. * Test [time=1385172503000L]
  29. * Test [time=1385105640000L]
  30. * Test [time=1376712950000L]
  31. */
  32.  
  33. }
  34.  
  35. private static class Test {
  36. long time;
  37.  
  38. public Test(long time) {
  39. super();
  40. this.time = time;
  41. }
  42.  
  43. @Override
  44. public String toString() {
  45. return "Test [time=" + time + "]";
  46. }
  47. }
  48.  
  49. // Ordena em ordem decrescente
  50. private static Comparator<Test> testDesc = new Comparator<Test>() {
  51. @Override
  52. public int compare(Test t1, Test t2) {
  53. return (int) (t2.time - t1.time);
  54. }
  55. };
  56. }
Success #stdin #stdout 0.07s 380160KB
stdin
Standard input is empty
stdout
Test [time=1376712950000]
Test [time=1385191974000]
Test [time=1385172503000]
Test [time=1385105640000]