I need to sort one array based on the arrangement of another array.
I fetch two arrays from somewhere and they are related.
Firstly, I need to sort the "name" array alphabetically. I can do that easily using "Arrays.sort(name)" but the problem is that my relationship with the "type" array will be lost. I need to re-order the "name" array alphabetically so that my "type" array also gets sorted automatically depending on the "name" array.
I would combine the 2 arrays into a Map or HashMap. Set the Map up to automatically sort alphabetically based on the "name" field. Afterwords if you really need 2 seperate arrays just extract them from the Map using Map.values().toArray(). Check out Map if you are unfamiliar. Also check out Comparable and Comparator examples to see how to automatically sort alphabetically.