如何对以下内容进行排序?
System.out.println("Title: " + titleArray[x].getBook());
此行从用户输入的标题中获取其数据。如果我试试
System.out.println("Title: " + Arrays.sort(titleArray[x].getBook()));
我收到以下错误:
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
我假设这是由于构造函数在返回时不允许排序? java.util.Arrays中;也是进口的。
编辑:尝试String sortedTitles [] = titleArray [x] .getBook();在Sysout之外为了建立一个新的字符串[],收到以下错误......
LibraryBookSort.java:63: error: incompatible types
String sortedTitles[] = titleArray[x].getBook();
^
required: String[]
found: String
1 error
如何对返回的数组进行排序?