Java错误:无法从void转换为int [] [英] Java Error: Cannot convert from void to int[]

查看:94
本文介绍了Java错误:无法从void转换为int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不明白为什么Java在将数组"thisRow"传递给Arrays.sort(thisRow)时认为它为空.对我来说,"thisRow"似乎是一个int [].这是什么问题?

I don't understand why java thinks the array "thisRow" is void when it is passed into Arrays.sort(thisRow). "thisRow" appears to be an int[] to me. What is the issue here?

错误消息:类型不匹配:在Test.mySort(Test.java:57)上无法从void转换为int []"

Error Message: "Type mismatch: cannot convert from void to int[] at Test.mySort(Test.java:57)"

private static int[][] mySort(int[][] anArray) {
    for(int i = 0; i < anArray.length; i++){
        int thisRow[] = getRow(anArray, i);
        int[] sorted = Arrays.sort(thisRow);
    }
}

//This method will get the specified row out of the array.
private static int[] getRow(int[][] anArray, int row) {
    int thisRow[] = new int[anArray[row].length];
    for(int j = 0; j < anArray[row].length; j++){
        thisRow[j] = anArray[row][j];
    }
    return thisRow;
}

推荐答案

根据javadoc

将指定的整数数组按升序排列.这排序算法是一种调优的快速排序方法,改编自Jon L. Bentley和道格拉斯·麦克罗伊(M. Douglas McIlroy)的设计排序功能",软件实践与经验,第一卷.23(11)P.1249-1265(11月1993).该算法可在许多数据集上提供n * log(n)性能导致其他快速排序的性能下降到二次方

Sorts the specified array of ints into ascending numerical order. The sorting algorithm is a tuned quicksort, adapted from Jon L. Bentley and M. Douglas McIlroy's "Engineering a Sort Function", Software-Practice and Experience, Vol. 23(11) P. 1249-1265 (November 1993). This algorithm offers n*log(n) performance on many data sets that cause other quicksorts to degrade to quadratic performance

替换

int[] sorted = Arrays.sort(thisRow);

Arrays.sort(thisRow);

这篇关于Java错误:无法从void转换为int []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆