I have this city class that i need sorted. Tried to find other posts but non actually helped because i could not use the Collections in the way that i wanted to use it. I have this array with integers that i want to sort, which is easy, but then i want to sort a string array in the same way as the integer array was sorted.
Tried to use collections but can only sort one array.
City(int i, String string) {
ArrayList<Integer> zipCode = new ArrayList<Integer>(); // This array is the integer.
zipCode.add(i);
i = Z;
this.i = i;
ArrayList<String> cityName = new ArrayList<String>();
cityName.add(string);
string = c;
}
public void list(String c) {
ArrayList<String> l = new ArrayList<String>(); // This is the string.
l.add(c);
// Here i want to be able to sort the string in the same order as the "zipCode"
// array or integer array.
for (String X : l) {
System.out.println(X);
}
}
Just expect to get the order correct, i can do everything else fine but it is the sorting that is bothering atm.
I am getting some strings of a city from my main class and some integers from the citys zip code, also from my main class. Somehow i want to be able to sort the whole array of string and int together by the values of the integers. But i don't see anyone else doing an this exact thing..
Zandcin the constructor? If you define theArrayListsin the constructor they are not available to thelistmethod...String[] array = {"foo", "bar"}this is list based on arrayList<String> list = new ArrayList<>(); list.add("foo"); list.add("bar");.