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 revisionPrevious revision
Next revision
Previous revision
java:jfc_intf_sorted_set_map [2017/02/07 21:24] – [java.util.SortedMap] gthanosjava:jfc_intf_sorted_set_map [2020/03/15 18:48] (current) – external edit 127.0.0.1
Line 10: Line 10:
   * **[[http://docs.oracle.com/javase/7/docs/api/java/util/SortedSet.html#subSet(E,%20E)|subSet(E fromElement, E toElement)]] - ** Επιστρέφει το υποσύνολο του Set από fromElement (μαζί με το fromElement) έως toElement (χωρίς το toElement).   * **[[http://docs.oracle.com/javase/7/docs/api/java/util/SortedSet.html#subSet(E,%20E)|subSet(E fromElement, E toElement)]] - ** Επιστρέφει το υποσύνολο του Set από fromElement (μαζί με το fromElement) έως toElement (χωρίς το toElement).
  
-<code java NameSortedSet.java> +<code java StudentSortedSet.java> 
-iimport java.util.*;+import java.util.*;
  
-public class NameSortedSet +public class StudentSortedSet 
-   static final Comparator<Name> NameOrdering =  +   
-                                        new Comparator<Name>() { +
-            public int compare(Name n1, Name n2) { +
-                int cmp = n1.firstName().compareTo(n2.firstName() ); +
-                return (cmp != 0 ? cmp : n1.lastName().compareTo(n2.lastName() )); +
-            } +
-    };+
  
-    public static void main(String[] args) { +  public static void main(String[] args) { 
-         +     
-        SortedSet<Namenames = new TreeSet<Name>(NameOrdering); +    SortedSet<Studentstudents = new TreeSet<Student>(); 
-        names.add(new Name("Bob", "Travolta")); +    students.add(new Student("John", "Smith")); 
-        names.add(new Name("John", "Smith")); +    students.add(new Student("Stanley", "Peters")); 
-        names.add(new Name("Karl", "Ng")); +    students.add(new Student("Edgar", "Bloch")); 
-        names.add(new Name("Jeff", "Smith")); +    students.add(new Student("Suzan", "Miles")); 
-        names.add(new Name("Tom", "Rich")); +    students.add(new Student("Mary", "Poppins")); 
-        for(Name n: names+    students.add(new Student("Tom", "Rich")); 
-          System.out.println(n); +    for(Student n: students
-           +      System.out.println(n); 
-        System.out.println("\n***Print headset***"); +       
-           +    System.out.println("\n***Print headset***"); 
-        SortedSet<Namesubnames names.headSet(new Name("Karl", "Ng")); +       
-        for(Name nsubnames+    SortedSet<StudentsubStudents students.headSet(new Student("Mary", "Poppins")); 
-          System.out.println(n); +    for(Student ssubStudents
-           +      System.out.println(s); 
-        System.out.println("\n***Print tailset***"); +       
-           +    System.out.println("\n***Print tailset***"); 
-        subnames names.tailSet(new Name("Karl", "Ng")); +       
-        for(Name nsubnames+    subStudents students.tailSet(new Student("Mary", "Poppins")); 
-          System.out.println(n); +    for(Student ssubStudents
-    }+      System.out.println(s); 
 +  }
 } }
 </code> </code>
java/jfc_intf_sorted_set_map.1486502643.txt.gz · Last modified: 2017/02/07 21:24 (external edit)