Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Person implements Comaparable<Person> {
- public Person(String name, int age) {
- this.name = name;
- this.age = age;
- }
- public String getName() { return this.name; }
- public int getAge() { return this.age; }
- /** Sorts Person objects by name, then age */
- public int compareTo() {
- // image a reasonable compareTo implemementation
- }
- }
- // Some version of Java with no Comparable (and also assuming no Comparator, either)
- public class SomeService {
- public List<Person> queryPeople(boolean sort) {
- List<People> people = findPeople();
- if (sort) {
- Collections.sort(people);
- }
- return people;
- }
- }
Add Comment
Please, Sign In to add comment