﻿ 在Java中同时对三个ArrayLists进行排序的最有效方法是什么？ - 代码日志

#### 在Java中同时对三个ArrayLists进行排序的最有效方法是什么？

``````public class MyBubbleSort {

public static void bubble_srt(List<Integer> score, List<String> name, List<Integer> pic) {
int n = score.size();
int k;
for (int m = n; m >= 0; m--) {
for (int i = 0; i < n - 1; i++) {
k = i + 1;
if (score.get(i) < score.get(k)) {
swapNumbers(i, k, score, name, pic);
}
}
printNumbers(score);
}
}

private static void swapNumbers(int i, int j, List<Integer> score, List<String> name, List<Integer> pic) {

int temp;
temp = score.get(i);
score.set(i, score.get(j));
score.set(j, temp);

String s;
s = name.get(i);
name.set(i, name.get(j));
name.set(j, s);

int p;
p = pic.get(i);
pic.set(i, pic.get(j));
pic.set(j, p);

}

private static void printNumbers(List<Integer> input) {

for (int i = 0; i < input.size(); i++) {
System.out.print(input.get(i) + ", ");
}
System.out.print("\n");
}

}
``````

``````package test;

public class PlayerInfo {

private String name;
private Integer score;
private Integer pictureId;

public PlayerInfo(final String name, final Integer score, final Integer pictureId) {
this.name = name;
this.score = score;
this.pictureId = pictureId;
}

public String getName() {
return this.name;
}

public void setName(final String name) {
this.name = name;
}

public Integer getScore() {
return this.score;
}

public void setScore(final Integer score) {
this.score = score;
}

public Integer getPictureId() {
return this.pictureId;
}

public void setPictureId(final Integer pictureId) {
this.pictureId = pictureId;
}

@Override
public String toString() {
return this.name + ":" + this.score + ":" + this.pictureId;
}
}
``````

``````package test;

import java.util.Comparator;

public class ScoreBasedComparator implements Comparator<PlayerInfo> {

@Override
public int compare(final PlayerInfo playerInfo1, final PlayerInfo playerInfo2) {
return playerInfo1.getScore().compareTo(playerInfo2.getScore());
}

}
``````

``````package test;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;

public class Runner {

public static void main(final String[] args) {
List<PlayerInfo> playerInfos = new ArrayList<PlayerInfo>();
Collections.sort(playerInfos, new ScoreBasedComparator());
System.out.println(Arrays.toString(playerInfos.toArray()));
}

}
``````

``````[B:1:2, C:23:3, A:123:1, D:300:4]
``````