Biblioteca Java - Blame information for rev 2
Subversion Repositories:
Rev | Author | Line No. | Line |
---|---|---|---|
2 | mihai | 1 | package colectii.set; |
2 | import java.util.TreeSet; | ||
3 | |||
4 | public class testSort { | ||
5 | public static void main(String[] args) { | ||
6 | TreeSet t = new TreeSet(); | ||
7 | Person p1 = new Person("jon",4); | ||
8 | Person p2 = new Person("alin",10); | ||
9 | Person p3 = new Person("dan",8); | ||
10 | Person p4 = new Person("florin",7); | ||
11 | t.add(p1);t.add(p2);t.add(p3);t.add(p4); | ||
12 | System.out.println(t); | ||
13 | System.out.println("firs:"+t.first()); | ||
14 | System.out.println("last:"+t.last()); | ||
15 | System.out.println("subset:"+t.subSet(new Person("x",5),new Person("y",9))); | ||
16 | System.out.println("headset:"+t.headSet(p3)); | ||
17 | } | ||
18 | } | ||
19 | |||
20 | class Person implements Comparable{ | ||
21 | int age; | ||
22 | String name; | ||
23 | Person(String n,int a){ | ||
24 | age = a; | ||
25 | name = n; | ||
26 | } | ||
27 | |||
28 | public int compareTo(Object o) { | ||
29 | Person p = (Person)o; | ||
30 | if(age>p.age) return 1; | ||
31 | if(age==p.age) return 0; | ||
32 | return -1; | ||
33 | } | ||
34 | |||
35 | public String toString(){ | ||
36 | return "("+name+":"+age+")"; | ||
37 | } | ||
38 | } |