Hello, I am writing a database in Java and trying to sort by place.
private void sortByPlace() { ArrayList<String> tmpplace = place; Collections.sort(place); for (int i = 0; i < place.size(); i++) { name.set(i, name.get(tmpplace.indexOf(place.get(i)))); surname.set(i, surname.get(tmpplace.indexOf(place.get(i)))); } printDB(); menu(); } The algorithm is as follows:
1) I create a temporary list tmpplace and write place to it.
2) Sort place.
3) I change the name and surname so that they correspond to the changed place.
Why tmpplace.indexOf (place.get (i)) = i? Thank you in advance.
new ArrayList<>(place);- etki