In Java 5, If i have a Set, and i add two objects to the Set. When I retrieve the objects, will it give me back in the same order as I added?
I am not able to find the answer to this. Does it depend on which Set implementation I use?
In Java 5, If i have a Set, and i add two objects to
Share
Yes, it depends on which implementation you use. For example,
LinkedHashSetwill preserve insertion order:… but
HashSetwon’t: