Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.itschool;
- import java.util.Comparator;
- public class Student{
- private String name;
- private int num;
- public Student(String name, int num){
- this.name = name;
- this.num = num;
- }
- @Override
- public String toString() {
- return "Student{" +
- "name='" + name + '\'' +
- ", num=" + num +
- '}';
- }
- public int getNum() {
- return num;
- }
- public String getName() {
- return name;
- }
- static class StudentCompare implements Comparator<Student> {
- @Override
- public int compare(Student o1, Student o2) {
- if(o1.getNum() > o2.getNum())
- return 1;
- else if(o1.getNum() < o2.getNum())
- return -1;
- return o1.getName().compareTo(o2.getName());
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement