Hi,
I want to search in a Set without iterating manually over the elments but there does not seem to be a method to do Collections.search(myset, target, new ComparatorThing()). Am I not seeing something?
Thanks.
Edit:
- I am searching for another field than the natural order of the elements.
- As a manual workaround I used the following static method. Should okay, since you can't make any assumtions about the other using a custom field in the comparator anyways.
public static T search(final Set set, final T searchEntry, final Comparator comparator) {
for (final T entry : set) {
if (comparator.compare(entry, searchEntry) == 0) {
return entry;
}
}
return null;
}