How to "copy" an array operation to another array?

arrays, java

Solution

Create a class like:

public class XYPos implements Comparable<XYPos> {
    int x;
    int y;

    @Override
    public int compareTo(XYPos o) {
        int res = this.y - o.y;
        if(res == 0) {
            res = this.x - o.x;
        }
        return res;
    }
}

Then:

- convert your 2 arrays into one array of `XYPos`

- sort it

- update your 2 original arrays with the values in the sorted array

Problem

This is probably a simple question, but I have two arrays of approx 1000 elements each, they are called `posXArray` and `posYArray`. I want to sort `posYArray` numerically (lowest number first) but I want the elements of `posXArray` to have the same operation applied to them... For example, if element [56] of `posYArray` is the smallest one , I want element [56] of `posXArray` to also be moved to [0]. How is this implemented in Java in an easy/good way? Thank you very much for you help!

Original source