Java tutorial
//package com.java2s; import java.util.*; public class Main { public static <T> void sortWithIndexesComparator(final List<T> list, final Comparator<Integer> comparator) { Collections.sort(list, new Comparator<T>() { @Override public int compare(T lhs, T rhs) { return comparator.compare(list.indexOf(lhs), list.indexOf(rhs)); } }); } }