Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. import java.util.Arrays;
  2. import java.util.*;
  3.  
  4. public class Main {
  5. public static void main(String args[])
  6. {
  7. Test stud[]=new Test[5];
  8. stud[0]=new Test("Ion",200);
  9. stud[1]=new Test("Marian",230);
  10. stud[2]=new Test("Alexandru",435);
  11. stud[3]=new Test("Alexandru",1);
  12. stud[4]=new Test("Spaghete",32);
  13.  
  14. for(int i=0;i<stud.length;i++)
  15. {
  16. System.out.println(stud[i]);
  17. }
  18.  
  19. Arrays.sort(stud,new Comparator<Test>()
  20. {
  21. public int compare(Test t1,Test t2)
  22. {
  23. if(t1.get_suma()>t2.get_suma())
  24. {
  25. return 1;
  26. }
  27. if(t1.get_suma()<t2.get_suma())
  28. {
  29. return -1;
  30. }
  31. return 0;
  32. }
  33. });
  34.  
  35. System.out.println();
  36.  
  37. for(int i=0;i<stud.length;i++)
  38. {
  39. System.out.println(stud[i]);
  40. }
  41.  
  42. List listuta=new ArrayList<Integer>();
  43. for(int i=0;i<stud.length;i++)
  44. {
  45. listuta.add(stud[i]);
  46. }
  47.  
  48. Collections.sort(listuta,new Comparator<Test>()
  49. {
  50. public int compare(Test t1,Test t2)
  51. {
  52. if(t1.get_nume()==t2.get_nume())
  53. {
  54. if(t1.get_suma()>t2.get_suma())
  55. {
  56. return 1;
  57. }
  58. else if(t1.get_suma()<t2.get_suma())
  59. {
  60. return -1;
  61. }
  62. }
  63. else if(t1.get_nume()!=t2.get_nume())
  64. {
  65. return t1.get_nume().compareTo(t2.get_nume());
  66. }
  67. return 0;
  68. }
  69. });
  70.  
  71. for(int i=0;i<listuta.size();i++)
  72. {
  73. System.out.println(listuta.get(i));
  74. }
  75.  
  76. }
  77. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement