Collections自定义List排序规则
//这里的顺序,是我自己定义的一个List<String>
String[] regulation = {"jams","buke","rose","lua"};
final List<String> regulationOrder = Arrays.asList(regulation);
String[] ordered = {"rose","jams","lua","rose","buke","jams","rose","buke","jams"};
List<String> orderedList = Arrays.asList(ordered);
Collections.sort(orderedList, new Comparator<String>()
{
public int compare(String o1, String o2)
{
int io1 = regulationOrder.indexOf(o1);
int io2 = regulationOrder.indexOf(o2);
return io1 - io2;
}
});
System.out.println(orderedList);