give me the pseudo code for hashmap in java to understand the functionality of hashmap

give me the pseudo code for hashmap in java to understand the functionality of hashmap
LVL 9
Manikandan ThiagarajanSenior consultantAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

for_yanCommented:
What do you mean by pseudo-ccode ?
You probably don't need pseudocode of the methods to understand functionality and to use HashMap

Hashmap is really not that difficult - this is an object that allows to
maintain corresspondence between the keys and the values.
Objects of any type (buit ono-primitive) could server as keys and as values.
Each key can have only one associated value (but of course several different keys can point to the same value).

And there are two main methods

put(Object key, Object value) - this method adds a new pair to a set of assocciatioopns which you may already have in th e HasMap

and another method

get(Object key)

this will retuen the vlaue Object correspnding to the provided key

As each key can have only one value
if you call put(key, vlaue) with the value of key which already exsists in the HashMap
you'll overwrite the previous pair with the same key


For more deatils read the preamble of the API doc for HashMap
http://download.oracle.com/javase/6/docs/api/java/util/HashMap.html

HashMap along with the ArrayList is I believe one of the most uused collections in Java
priogramms as indeed very often in programming situations it is convenient to
establsih this kind of correspodedce between two sets of objects

Let me know if you have any questions about it.







Manikandan ThiagarajanSenior consultantAuthor Commented:
give me the pseudo code for how to store the value in hashmap and how to retreive that one
for_yanCommented:

This is how you put:
HashMap<String,String> m = new HashMap<String,String>();
m.put("a","b");
String s0 = "c";
String s1 = "d";
m.put(s0,s1);

This is how you retrieve:

String res = m.get("a");

res will be equal to  "b" in this case.

String res1 = m.get(s0);

res1 will be equal to "d";

Open in new window

Become a Microsoft Certified Solutions Expert

This course teaches how to install and configure Windows Server 2012 R2.  It is the first step on your path to becoming a Microsoft Certified Solutions Expert (MCSE).

Manikandan ThiagarajanSenior consultantAuthor Commented:
How to iterate hashmap from for loop
for_yanCommented:

HashMap<String,String> m = new HashMap<String,String>();
m.put("a","b");
String s0 = "c";
String s1 = "d";
m.put(s0,s1);

for (String ss : m.keySet()){
Systemn.out.println(ss + "  " + m.get(ss));

}

Open in new window

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
for_yanCommented:
  method keySet() returns Set which you can iterate and then retrieve corresponding values
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Java

From novice to tech pro — start learning today.