1

Possible Duplicate:
How do I sort two arrays in relation to each other?

I have 2 two String[] arrays. I want to sort 2nd array with index same with the 1st array.

private void checkDatabase(String keyword, String origins) {
    List<RSList> rslist = db.getAllRSListsByType(keyword);

    total = rslist.toArray().length;

    String[] titlearray = new String[total];
    String[] distance = new String[total];

    int i = 0;
    for (RSList cn : rslist) {
        titlearray[i] = cn.getName();
        String origin = origins;
        String destination = cn.getGlat() + "," + cn.getGlon();
        distance[i] = checkDataToGoogle(origin, destination);
        Log.i("Name: ", distance[i]);
        i++;
    }
    Arrays.sort(distance);
    filldata(titlearray, distance);
}

I want to make index of titlearray same with distance array, I already sort the distance array first, but I don't know how to make order of titlearray same with distance.

Can anyone give me advice?

Don Vincent
  • 466
  • 4
  • 15
  • Using standard Java sorting you will need to create (or find) a suitable Composite Type and then either implement `Comparable` or create a custom `Comparator`. –  Jan 23 '13 at 03:02
  • Pls see [Sort one List<> based on another](http://stackoverflow.com/a/14227784), diff language though – Karthik T Jan 23 '13 at 03:02
  • @pst One suggestion that would apply is to rethink/rework the data structures if possible to unify the 2 arrays into 1.. – Karthik T Jan 23 '13 at 03:04
  • Also see http://stackoverflow.com/questions/4839915/sorting-a-list-based-on-another-lists-values-java , http://stackoverflow.com/questions/2689455/sort-an-object-by-an-other-one?rq=1 –  Jan 23 '13 at 03:07

0 Answers0