Given the Set object, I want to go through all of its (unordered) pairs.
Example: Set = {1, 2, 3}, pairs: (1, 2), (1, 3), (2, 3).
When working with Vector<Integer> this can be achieved using the index of each element:
for (int i = 0; i < vector.size(); i++) for (int j = i + 1; j < vector.size(); j++)
But the elements in Set<Integer> have no indexes.
The best solution I've found so far is to convert Set to Vector and use the above solution.
Is there a more efficient / direct solution?
java set pair
John threepwood
source share