//给List排序并且记录位置
{
int[] b = {0,0,2,1,1,2};
int[] bcopy = new int[b.length];
for (int i = 0; i < b.length; i++) {
bcopy[i] = b[i];
}
Arrays.sort(bcopy);
System.out.println("排序之前的序列为:" + Arrays.toString(b));
System.out.println("排序之后的序列为:" + Arrays.toString(bcopy));
List<Integer> locationList = new ArrayList<>();
for (int i = 0; i <b.length; i++) {
for (int j = 0; j <bcopy.length; j++) {
if (bcopy[i] == b[j] ){
System.out.println("排序之后的序列中 "+ bcopy[i] +" 的索引为:" +j);
locationList.add(j);
b[j] = 999999; //取一个在原序列中取不到的值
}
}
}
System.out.println(locationList);
}
给List排序并且记录位置
最新推荐文章于 2021-07-03 16:16:12 发布