Skip to content
Advertisement

Tag: any

Good way to get *any* value from a Java Set?

Given a simple Set<T>, what is a good way (fast, few lines of code) to get any value from the Set? With a List, it’s easy: But, with a Set, there is no .get(…) method because Sets are not ordered. Answer A Set<T> is an Iterable<T>, so iterating to the first element works: Guava has a method to do this,

Advertisement