0
2番目の要素に基づいて2dのArraylistをソートしようとしています。2つの要素に基づいて2dのarraylistをソート
だから私のArrayListのは
[[1, 4, 0], [2, 5, 2], [3, 5, 3], [4, 3, 6]]
のように見えると私はそれがあまりにもこれはこれは私がこれまで使ってきたものである私のArrayList
ArrayList<ArrayList<Integer>> processes = new ArrayList<>();
あるこの
[[4, 3, 6], [1, 4, 0], [2, 5, 2], [3, 5, 3]]
のようになりたいです選択ソート
int smallInt;
int j;
int smallIntIndex;
for(int i = 1; i<=processes.size();i++){
smallInt = processes.get(i-1).get(1);
smallIntIndex = i-1;
for(j=i;j<processes.size();j++){
if(processes.get(j).get(1)==smallInt){
//not exactly sure what goes in here
}else if(processes.get(j).get(1)<smallInt){
smallInt = processes.get(j).get(1);
smallIntIndex = j;
}
}
ArrayList<Integer> temp = processes.get(smallIntIndex);
processes.set(smallIntIndex,processes.get(i-1));
processes.set(i-1,temp);
}
[[4,3,6]、[1,4,0]、[2,5,2]、[3,5,3]]はどのようにソートされていますか? – robotlos
第1要素(ネストされた配列リストの第1インデックス)に基づいてソートされます。 –
'processes.sort(firstElement、secondElement) - > Integer.compare(firstElement.get(1)、secondElement.get(1)); ' – Palle