zur vorherigen Seite   zum Inhaltsverzeichnis   zur nächsten Seite

Antwort:

Nein.

Integer Sortier-Programm

Hier ist ein Programm, das die Klassenmethode static void sort(int[]) der Klasse Arrays verwendet. Die Methode ist static, so dass sie verwendet werden kann, ohne ein Arrays-Objekt zu erstellen.

import java.util.Arrays;

class ArrayDemoOne
{
  public static void main(String[] args)
  {
    int[] scramble =
      {148, -23, 67, 110, -17, 44, 103, -12, -8, 91,
       -12, 43, 0, 9, 80, 34, 21, 44, 15, 11};

    System.out.print("Scrambled array: ");
    for (int j=0; j < scramble.length; j++)
      System.out.print( scramble[j] + " ");

    System.out.println();

    Arrays.sort(scramble);

    System.out.print("Sorted array: ");
    for (int j=0; j < scramble.length; j++)
      System.out.print(scramble[j] + " ");

    System.out.println();

  }
}

Die Ausgabe des Programms ist:

Scrambled array: 148 -23 67 110 -17 44 103 -12 -8 91 -12 43 0 9 80 34 21 44 15 11
Sorted    array: -23 -17 -12 -12 -8 0 9 11 15 21 34 43 44 44 67 80 91 103 110 148

FRAGE 14:

Könnte compareTo() verwendet werden, um ein Array von String-Referenzen zu sortieren?

zur vorherigen Seite   zum Inhaltsverzeichnis   zur nächsten Seite