Because sets have no ordering. Some implementations do (particularly those implementing the java.util.SortedSet
interface), but that is not a general property of sets.
If you’re trying to use sets this way, you should consider using a list instead.
More Related Contents:
- How to convert an Array to a Set in Java
- Getting an element from a Set
- What is the best way to combine two lists into a map (Java)?
- What is the best way get the symmetric difference between two sets in java?
- Best way to create a hashmap of arraylist
- Removing items from a collection in java while iterating over it
- Any implementation of Ordered Set in Java?
- ArrayList Vs LinkedList
- Classical set operations for java.util.Collection
- Why does TreeSet throw a ClassCastException?
- Automatically sorted by values map in Java
- Performance and Memory allocation comparison between List and Set
- What is the difference between "collection" ,"Collection" and "Collections"? [duplicate]
- Difference between
- Properly removing an Integer from a List
- How do I convert a Map to List in Java?
- Randomly select an item from a list
- Define a fixed-size list in Java
- How to shuffle an ArrayList [duplicate]
- How can I generate a list or array of sequential integers in Java?
- Java: Avoid inserting duplicate in arraylist
- what’s a good persistent collections framework for use in java?
- Is there a way to get the value of a HashMap randomly in Java?
- Difference between a deprecated and a legacy API?
- JDK9 randomization on immutable sets and maps
- In what situations is the CopyOnWriteArrayList suitable? [duplicate]
- What Java 8 Stream.collect equivalents are available in the standard Kotlin library?
- Create a List of primitive int?
- Java collections covariance problem
- How to do map inversion with Guava with non-unique values?