How to sort multiple ArrayLists arrays all together in java

I am working on an application that stores information about restaurants, each restaurant has 5 information "as indicated in the code below", I need to sort the restaurants according to the rate. However, after sorting by speed, I need to synchronize all the lists of arrays together so that their information matches correctly.

I have 5 ArrayLists, I need to sort one of them, but I also want to change the indices of the 4 other ArrayLists to match each other. I tried the list of maps, but it tells me that I can do this with only two parameters, not 5.

Here are my ArrayLists:

//******* Arrays that holds information of restaurants taken from SERVER
static public ArrayList<String> name = new ArrayList<String>();
static public ArrayList<String> lng = new ArrayList<String>();
static public ArrayList<String> lat = new ArrayList<String>();
static public ArrayList<String> address = new ArrayList<String>();
static public ArrayList<String> rate = new ArrayList<String>();
static public ArrayList<String> comment = new ArrayList<String>();
//private Map<String, String> sorted = new HashMap<>(); Doesn't work with 5 parameters

I need to sort the list of speeds, but also change the indices of others.

+4
1

objet, . , , .

Comparable Restaurant, , .

:

:

public class Restaurant implements Comparable<Restaurant>{

    private String name;
    private String lng;
    private String lat;
    private String address;
    private String rate;
    private String comment;

    ...
    constructor/getters/setters
    ...

    @Override
    public int compareTo(Restaurant rest) {
        //TODO: check if rate is null if this can happen in your code
        return rate.compareTo(rest.rate); //comparing on rate attribute
    }

}

static public ArrayList<Restaurant> restaurants = new ArrayList<Restaurant>();
Collections.sort(restaurants);
+4

All Articles