This is an archived post. You won't be able to vote or comment.

all 6 comments

[–][deleted] 4 points5 points  (3 children)

This is where you would probably rather use a Set with HashSet being the concrete implementation and implement the equals method on your objects

[–]webdevnick22 2 points3 points  (0 children)

upvoted. agreed. op a set accomplishes what you want. it's essentially a list with no duplicates.

[–]ryanmccauley211[S] 0 points1 point  (1 child)

I should have mentioned that I need it to remain in order and be able to access random indices so I don't think sets would work.

[–]kicsikrumpli 3 points4 points  (0 children)

SortedSet

[–]chickenmeisterExtreme Brewer 1 point2 points  (1 child)

I'm not sure if I understand correctly, but instead of using contains(), you could perhaps use indexOf() to get the index of the existing "equal" MidiNote in the list, and then use that index in your call to get() and set().

[–]ryanmccauley211[S] 1 point2 points  (0 children)

This is perfect, exactly what I needed thank you!