Given an array of four Points produce a new array/vector/arraylist (whatever is easier) with the same Points but if there are Points with duplicate X values, only save the Point which has the highest Y value.
For example:
If given (3, 2), (3, 1), (1, 2), (1, 1) this method should output only (3, 2) and (1, 2).
If given (3, 2), (3, 3), (3, 4), (3, 5) this method should output only (3, 5).
Any ideas on how I should proceed with this? My solutions keep running into a ConcurrentModificationException.
(for each point a in array) {
(for each point b in newArray) {
(if a and b have the same x and a has a greater y) {
remove a
add b
} else {
add b
}
}