I have two arrays, one stores the distance of the cities and the other stores the corresponding population. Everything works fine if the distance of the cities is in ascending o
A "cheap" way would be to have a third array which would contain 0 to n representing the index of the other arrays
But the problem you are having would disappear if they were grouped in a class, both information seem logically related. Then you would implement Comparable: https://stackoverflow.com/a/18896422