Ritesh raushan wrote:i asked because the two methods of map returns Set why not List.
Matthew's quite right about why Sets make more sense, but for keySet() this is mainly because Java chose to make Map keys unique - my guessing is for simplicity and consistency. There are Map structures (such as "tree"- and skiplist-based maps) for which this is NOT a fundamental requirement. That said, mappings (key-value pairs) should generally be unique; so entrySet() does make a lot of sense.
It's also possible to set up a Map where the "element index" is the key; however, this is more akin to a sparse array than a List, because insertion and removal, even from the middle of the "list" doesn't affect the indexes of other elements.
You might also want to have a look at Multimaps, which allow a key to represent more than one value. At present, Java doesn't include an implementation for one though.
Bats fly at night, 'cause they aren't we. And if we tried, we'd hit a tree -- Ogden Nash (or should've been).
Articles by Winston can be found here