Forums Register Login

How is order working in a Collection?

+Pie Number of slices to send: Send
This class is ordered by name but what does it happen when various objects have the same name?



Result:

Which object is the first? Depends on value, hashcode..?
+Pie Number of slices to send: Send
It depends on the original order of the list which affects the order compare to is run. In other words, you shouldn't rely on the order. It isn't guaranteed and future implementations of the JDK could change it.
It was the best of times. It was the worst of times. It was a tiny ad.
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com


reply
reply
This thread has been viewed 855 times.
Similar Threads
print m1 m2 m3 in 3 different threads in sequence
Set that only Items can be added
Problem with using variable before it is defined
HashMap
Mock question from SCJP book
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 18, 2024 20:04:24.