Java HashMap

Java HashMap is under java.util. – Java API

1. What is HashMap?
HashMap is an Object that stores both “key/value” as a pairs. In this article, we show how to create a HashMap instance and iterates the HashMap data.
—> put(“key”, “value”);  // set the value
—> get(“key”);  // get the value

import java.util.HashMap;
import java.util.Map;
// Frank Nandong(08/05/2014)
// franknandong@gmail.com / fndong@wordpress.com
// Task : one key been pick from two keys, get the value.

public class Hasmap_one {
public static String sPickValue = “”;

public static void main(String args[]){
Map mMap = new HashMap();

// add the key and value of the dessert

mMap.put(“banana”, “icecream Banana”);
mMap.put(“apple”, “apple pie”);

// pick the apple key , to get value “apple pie”
// convert object to string by put (String) betwen mMap.get(“apple”)

sPickValue = (String)mMap.get(“apple”);

// output display

System.out.println(“I Pick apple key , the value is : ” + sPickValue);
}
}

2

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s