Hey,
Even I am trying this section of java, and I have a example just have a look at it
Code:
Map mp = new HashMap();
mp = new TreeMap(); // sorted mp
// Add key/val pairs to the mp
mp.put("x", new Integer(1));
mp.put("y", new Integer(2));
mp.put("z", new Integer(3));
// Get number of entries in mp
int size = mp.size(); // 2
// Adding an entry whose key exists in the mp causes
// the new val to replace the old val
Object odval = mp.put("x", new Integer(9)); // 1
// Remove an entry from the mp and
// return the val of the removed entry
odval = mp.remove("c"); // 3
// Iterate over all keys in the table
Iterator it = mp.keySet().iterator();
while (it.hasNext()) {
// Retrieve key
Object key = it.next();
}
// Iterate over all vals in table
it = mp.vals().iterator();
while (it.hasNext()) {
// Get val
Object val = it.next();
}
Bookmarks