最近,当做大学的任务时,我遇到的一件事是排序和搜索一个2D数组。 使用Arrays.sort(example);
或Arrays.binarySearch(example, "xyz");
返回错误:java二维数组 - 排序和搜索
example cannot be cast to java.lang.Comparable
代替二进制搜索的,我不得不嵌套的for循环使用,虽然我也喜欢做的有效途径。
我的另一个问题是使用Arrays.asList(example).contains("xyz");
,它似乎从来没有工作。然后我用System.out.println(Arrays.asList(example));
来检查什么是错的。这是我的了:
[[[email protected], [[email protected], [[email protected], [[email protected], [[email protected], [[email protected], [[email protected], [[email protected], [[email protected], [[email protected]]
那是什么,最重要的是什么是解决这些问题的最佳方式是什么?
而跟进的问题 - 为什么有些错误(如example cannot be cast to java.lang.Comparable
只出现一次的程序运行,而不是当它被编译
任何帮助是非常赞赏
如果你表现出一些更多的代码的这会有所帮助,具体在哪里,你填充阵列和什么 – tddmonkey
排序的二维数组没有什么意义。你会如何分类'{{1,4},{2,3}}?“? +++ *与二进制搜索相比,我不得不使用嵌套for循环,尽管我希望这样做的有效方式。* - 二进制搜索是有效的,但只在已经*排序的数组上。如果添加分类成本,则不支付。 – maaartinus