I have an object with the following memebers:
class XNode {
    // key
    long magicNumber;   
    // metadata:
    int x;
    iny y;
    int z;
    double angle;
    double tempreture;
}
I want to use order list (the key is magicNumber).
Is there a list in java which already implements the add/remove/update in a order manner ? (I dont want to use Collections.sort for every operation).
no duplicates are allowed
First, in XNode there is a typo. I believe
iny y;
should be
int y;
Then you might use a SortedSet (for example TreeSet),
Comparator<XNode> comp = new Comparator<XNode>() {
    @Override
    public int compare(XNode o1, XNode o2) {
        return Long.valueOf(o1.magicNumber).compareTo(o2.magicNumber);
    }
};
SortedSet<XNode> set = new TreeSet<>(comp);
                        If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With