How to extract HashMap values?

Answer Posted / srikanth

package com.sri;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;

public class entry {

public static void main(String[] args) {
try{
HashMap<Integer,Integer>tm=new
HashMap<Integer,Integer>();
tm.put(100,200);
tm.put(200,101);
tm.put(600,700);
tm.put(700,103);
tm.put(900,104);
Set s=tm.entrySet();
Iterator it=s.iterator();
while(it.hasNext()){
Map.Entry me=(Map.Entry)it.next();
System.out.println(me.getKey()
+"......"+me.getValue());
}
}catch(Exception e){
e.printStackTrace();
}
}

}


Is This Answer Correct ?    3 Yes 0 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

Why we use set in java?

520


What is java util function?

517


Differentiate between nested and inner class in java.

559


what is use of functional interface in java 8?

561


Why does java have different data types for integers and floating-point values?

538






What are advantages and disadvantages of OOPs?

630


Can one thread block the other thread?

609


Describe method overriding

589


What are the important features of Java 10 release?

513


What is the private method modifier?

585


What is java reflection api?

560


What do you understand by casting in java language?

580


Why 1 is not a prime number?

562


Why multiple inheritance is not supported by java?

516


What is the largest number a double can hold?

567