Advertisement
Guest User

Untitled

a guest
Apr 21st, 2019
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.47 KB | None | 0 0
  1. import java.util.ArrayList;
  2. import java.util.Collections;
  3.  
  4. public class ListOfHumans {
  5. public static void main(String[] args) {
  6. Student s1 = new Student("Вероника", "Зорина");
  7. Student s2 = new Student("Алиса", "Истомина");
  8. Educator e1 = new Educator("Светлана", "Чистякова");
  9. Magistrant m1 = new Magistrant("Григорий", "Геращенко");
  10.  
  11. ArrayList<Human> list = new ArrayList();
  12. list.add(s1);
  13. list.add(s2);
  14. list.add(e1);
  15. list.add(m1);
  16.  
  17. System.out.println("До сортировки:");
  18. for (Human human : list) {
  19. System.out.println(human);
  20. }
  21.  
  22. System.out.println();
  23. System.out.println("Сортировка студентов по фамилии и имени");
  24. ArrayList array = Human.createArrayOfStudents(list);
  25. Collections.sort(array, Human::compareTo);
  26. for (Human u : list) {
  27. System.out.println(u);
  28. }
  29.  
  30. System.out.println();
  31. Collections.sort(array, new MyComparator());
  32. for (Human u : list) {
  33. System.out.println(u);
  34. }
  35.  
  36. System.out.println();
  37. System.out.println("Сортировка всех по фамилии и имени:");
  38. Collections.sort(list, Human::compareTo);
  39. for (Human u : list) {
  40. System.out.println(u);
  41. }
  42.  
  43. }
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement