Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class TEsr {
- List<Person> set = new ArrayList();
- public static void main(String[] args) throws IOException {
- TEsr tesr = new TEsr();
- tesr.go();
- }
- public void go() throws IOException {
- set.add(new Person("Maks",42,true));
- set.add(new Person("Andy",22,false));
- set.add(new Person("Lex",99,false));
- set.add(new Person("Mary",18,false));
- if(set.isEmpty()) {
- throw new IOException("collection is empty");
- }
- else {
- Collections.sort(set, new Sort());
- set.remove(3);
- set.remove(2);
- set.remove(1);
- System.out.println(set);
- }
- }
- }
- class Person {
- String name;
- int age;
- boolean men;
- Person(String name,int age,boolean men) {
- this.age = age;
- this.name = name;
- this.men = men;
- }
- public String toString()
- {
- return this.age + " " + this.name +
- " " + this.men;
- }
- }
- class Sort implements Comparator<Person> {
- public int compare(Person a, Person b)
- {
- return b.age - a.age;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement