User Tools

Site Tools


java:jfc_intf_sorted_set_map

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Next revision Both sides next revision
java:jfc_intf_sorted_set_map [2015/03/23 07:37]
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 java.util.*;+import java.util.*;
  
 public class NameSortedSet { public class NameSortedSet {
    static final Comparator<Name> NameOrdering =     static final Comparator<Name> NameOrdering = 
-                                        new Comparator<Name>() { +                    new Comparator<Name>() { 
-            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() )); 
-            +      
-    };+  };
  
-    public static void main(String[] args) { +  public static void main(String[] args) { 
-         +     
-        SortedSet<Name> names = new TreeSet<Name>(NameOrdering); +    SortedSet<Name> names = new TreeSet<Name>(NameOrdering); 
-        names.add(new Name("Bob", "Travolta")); +    names.add(new Name("Bob", "Travolta")); 
-        names.add(new Name("John", "Smith")); +    names.add(new Name("John", "Smith")); 
-        names.add(new Name("Karl", "Ng")); +    names.add(new Name("Karl", "Ng")); 
-        names.add(new Name("Jeff", "Smith")); +    names.add(new Name("Jeff", "Smith")); 
-        names.add(new Name("Tom", "Rich")); +    names.add(new Name("Tom", "Rich")); 
-        for(Name n: names) +    for(Name n: names) 
-          System.out.println(n); +      System.out.println(n); 
-           +       
-        System.out.println("\n***Print headset***"); +    System.out.println("\n***Print headset***"); 
-           +       
-        SortedSet<Name> subnames = names.headSet(new Name("Karl", "Ng")); +    SortedSet<Name> subnames = names.headSet(new Name("Karl", "Ng")); 
-        for(Name n: subnames) +    for(Name n: subnames) 
-          System.out.println(n); +      System.out.println(n); 
-           +       
-        System.out.println("\n***Print tailset***"); +    System.out.println("\n***Print tailset***"); 
-           +       
-        subnames = names.tailSet(new Name("Karl", "Ng")); +    subnames = names.tailSet(new Name("Karl", "Ng")); 
-        for(Name n: subnames) +    for(Name n: subnames) 
-          System.out.println(n); +      System.out.println(n); 
-    }+  }
 } }
 </code> </code>
Line 120: Line 120:
 </code> </code>
  
 +|Προηγούμενο: [[:java:jfc_intf_sort | Sorting  ]] | [[:toc | Περιεχόμενα ]] | Επόμενο: [[:java:jfc_algorithms| Αλγόριθμοι ]] |
java/jfc_intf_sorted_set_map.txt · Last modified: 2020/03/15 18:48 (external edit)