Java: Sortierung des Benutzereingabearrays bei der Rückgabe

Wie kann ich Folgendes sortieren?

System.out.println("Title: " + titleArray[x].getBook());

Diese Zeile bezieht ihre Daten aus einem vom Benutzer eingegebenen Titel. Wenn ich es versuche

System.out.println("Title: " + Arrays.sort(titleArray[x].getBook()));

Ich erhalte folgende Fehlermeldung:

  LibraryBookSort.java:66: error: no suitable method found for sort(String)
          System.out.println("Title: " + Arrays.sort(titleArray[x].getBook()));
                                             ^
  method Arrays.<T#1>sort(T#1[],int,int,Comparator<? super T#1>) is not applicable
  (cannot instantiate from arguments because actual and formal argument lists differ in length)
  method Arrays.<T#2>sort(T#2[],Comparator<? super T#2>) is not applicable
  (cannot instantiate from arguments because actual and formal argument lists differ in length)
  method Arrays.sort(Object[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(Object[]) is not applicable
  (actual argument String cannot be converted to Object[] by method invocation conversion)
  method Arrays.sort(double[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(double[]) is not applicable
  (actual argument String cannot be converted to double[] by method invocation conversion)
  method Arrays.sort(float[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(float[]) is not applicable
  (actual argument String cannot be converted to float[] by method invocation conversion)
  method Arrays.sort(byte[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(byte[]) is not applicable
  (actual argument String cannot be converted to byte[] by method invocation conversion)
  method Arrays.sort(char[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(char[]) is not applicable
  (actual argument String cannot be converted to char[] by method invocation conversion)
  method Arrays.sort(short[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(short[]) is not applicable
  (actual argument String cannot be converted to short[] by method invocation conversion)
  method Arrays.sort(long[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(long[]) is not applicable
  (actual argument String cannot be converted to long[] by method invocation conversion)
  method Arrays.sort(int[],int,int) is not applicable
  (actual and formal argument lists differ in length)
  method Arrays.sort(int[]) is not applicable
  (actual argument String cannot be converted to int[] by method invocation conversion)
  where T#1,T#2 are type-variables:
  T#1 extends Object declared in method <T#1>sort(T#1[],int,int,Comparator<? super T#1>)
  T#2 extends Object declared in method <T#2>sort(T#2[],Comparator<? super T#2>)
  1 error

Ich nehme an, das liegt daran, dass der Konstruktor bei der Rückkehr keine Sortierung zulässt. Java.util.Arrays; wird ebenfalls importiert.

BEARBEITEN: Nach dem Versuch, String zu sortierenTitles [] = titleArray [x] .getBook (); außerhalb des Sysout, um eine neue Zeichenfolge [] einzurichten, wurde die folgende Fehlermeldung angezeigt ...

  LibraryBookSort.java:63: error: incompatible types
        String sortedTitles[] = titleArray[x].getBook();
                                                     ^
  required: String[]
  found:    String
  1 error

Wie kann ich das zurückgegebene Array sortieren?

Antworten auf die Frage(0)

Ihre Antwort auf die Frage