排序使用Arrays.sort并行阵列() [英] Sort a parallel array using Arrays.sort()
本文介绍了排序使用Arrays.sort并行阵列()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否有可能使用 Arrays.sort()
来排序数组,然后有另外一个相关的阵列定位一样,例如排序数组:
Is it possible to sort an array using Arrays.sort()
and thereafter have another related array positioned the same as the sorted array for example:
String arrNames[] = new String[5];
String arrCellNo[] = new String[arrNames.length];
String arrNamesSorted[] = new String[arrNames.length];
System.arraycopy(arrNames, 0, arrNamesSorted, 0, arrNames.length);
Arrays.sort(arrNamesSorted);
从这点什么,我想要做的是排序 CellNo
阵列,这样,如果人进行了cellNoX,他将具有相同的cellNo X阵列后, arrNames
排序
From this point what i would like to do is sort the CellNo
array such that if "person" had a cellNo "x", he will have the same "cellNo" "x" after the array arrNames
is sorted
推荐答案
我会去一个不同的方法:
I would go for a different approach:
-
创建一个新的对象:
Create a new object:
public class Person {
private name;
private cellNo;
// Implement getters and setters
}
创建一个比较:
Create a comparator:
public MyComparator implements Comparator<Person> {
public int compare(Person a, Person b) {
return a.getName().compareTo(b.getName());
}
}
呼叫中的Array.sort(人,新MyComparator())
在人[] =的人...
阵列
这篇关于排序使用Arrays.sort并行阵列()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文