Thursday, August 20, 2009

HashMap & Arbitary number of arguments in java...

It's simple stuff - HashMap

let's say there is a hashmap of strings in java and given a key you want to retrieve the corresponding value - i thought one could do it just by passing the string -- No it does not work that way -

since the get method takes only an object as a parameter - so typically the way to do would be to get all the keys from the hashmap and the iterate over the keys to get the corresponding values --

Arbitary Number of Arguments in Java

I saw a method with the following signature today - public List getXYZ(String... categories) - was wondering what String... means - it can be used to pass arbitary number of arguments in java - here is the explanation....

http://java.sun.com/docs/books/tutorial/java/javaOO/arguments.html

No comments:

Post a Comment