How can I access a specific element in a Set
?
For example, in a Vector
I can access an element using vector.elementAt(i)
, but it doesn't work for a Set
.
Asked
Active
Viewed 48 times
0

Adelin Rau
- 11
- 1
-
3There is no elements order in ```Set``` structure. Therefore, you cannot get it like in ```Vector```. – Marcin Rzepecki Oct 28 '20 at 16:31
-
You can try to use ordered set implementation like ```TreeSet```, but I recommend you to consider changing structure for that task to some natively ordered, like ```List```. https://docs.oracle.com/javase/7/docs/api/java/util/TreeSet.htm – Marcin Rzepecki Oct 28 '20 at 16:37