java:comparable

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:comparable [2020/02/25 08:30]
gthanos [Το interface java.util.Comparator]
java:comparable [2020/02/26 21:11]
gthanos
Line 118: Line 118:
 <code java> <code java>
     Arrays.sort(rectangles, new RectangleComparator());     Arrays.sort(rectangles, new RectangleComparator());
 +</code>
 +
 +<code java SortRectangleArray.java>
 +import java.util.Random;
 +import java.util.Arrays;
 +
 +class SortRectangleArray {
 +  
 +    public static void main(String []args) {
 +    Random rand = new Random(12345);
 +    Rectangle []rectangles = new Rectangle[5];
 +    for(int i=0;i<5; i++)
 +      rectangles[i] = new Rectangle(rand.nextInt(10), rand.nextInt(10));
 +      
 +    print_rectangles(rectangles);
 +    Arrays.sort(rectangles, new RectangleComparator());
 +    print_rectangles(rectangles);
 +  }
 +  
 +  public static void print_rectangles(Rectangle []rectangles) {
 +    System.out.println("================");
 +    for(int i=0; i<rectangles.length; i++)
 +      System.out.println(i+". "+rectangles[i].toString());
 +  }
 +}
 </code> </code>
  
Line 126: Line 151:
 </WRAP> </WRAP>
  
 +| Προηγούμενο : [[ :java:abstract_classes_vs_interfaces | Σύγκριση abstract κλάσεων και interfaces ]] | [[ :toc | Περιεχόμενα ]] | Επόμενο: [[ :java:instanceof | Ο τελεστής instanceof ]]  |
java/comparable.txt · Last modified: 2020/03/15 18:30 (external edit)