This shows you the differences between two versions of the page.
| Both sides previous revision Previous revision | Next revision Both sides next revision | ||
|
java:jfc_intf_sorted_set_map [2017/02/07 21:24] gthanos [java.util.SortedMap] |
java:jfc_intf_sorted_set_map [2017/03/28 23:48] gthanos [java.util.SortedSet] |
||
|---|---|---|---|
| Line 11: | Line 11: | ||
| <code java NameSortedSet.java> | <code java NameSortedSet.java> | ||
| - | iimport | + | import |
| public class NameSortedSet { | public class NameSortedSet { | ||
| | | ||
| - | | + | |
| - | public int compare(Name n1, Name n2) { | + | public int compare(Name n1, Name n2) { |
| - | int cmp = n1.firstName().compareTo(n2.firstName() ); | + | int cmp = n1.firstName().compareTo(n2.firstName() ); |
| - | return (cmp != 0 ? cmp : n1.lastName().compareTo(n2.lastName() )); | + | return (cmp != 0 ? cmp : n1.lastName().compareTo(n2.lastName() )); |
| - | } | + | } |
| - | }; | + | }; |
| - | | + | |
| - | + | ||
| - | SortedSet< | + | SortedSet< |
| - | names.add(new Name(" | + | names.add(new Name(" |
| - | names.add(new Name(" | + | names.add(new Name(" |
| - | names.add(new Name(" | + | names.add(new Name(" |
| - | names.add(new Name(" | + | names.add(new Name(" |
| - | names.add(new Name(" | + | names.add(new Name(" |
| - | for(Name n: names) | + | for(Name n: names) |
| - | System.out.println(n); | + | System.out.println(n); |
| - | + | ||
| - | System.out.println(" | + | System.out.println(" |
| - | + | ||
| - | SortedSet< | + | SortedSet< |
| - | for(Name n: subnames) | + | for(Name n: subnames) |
| - | System.out.println(n); | + | System.out.println(n); |
| - | + | ||
| - | System.out.println(" | + | System.out.println(" |
| - | + | ||
| - | subnames = names.tailSet(new Name(" | + | subnames = names.tailSet(new Name(" |
| - | for(Name n: subnames) | + | for(Name n: subnames) |
| - | System.out.println(n); | + | System.out.println(n); |
| - | } | + | } |
| } | } | ||
| </ | </ | ||