Created
September 14, 2011 20:14
-
-
Save preslavrachev/1217650 to your computer and use it in GitHub Desktop.
Iterate through HashMap
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static void printMap(Map mp) { | |
Iterator it = mp.entrySet().iterator(); | |
while (it.hasNext()) { | |
Map.Entry pairs = (Map.Entry)it.next(); | |
System.out.println(pairs.getKey() + " = " + pairs.getValue()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Funciona bien tu método. Your method works well.
import java.util.*;
public class Prueba{
//your method works well
public static void printMap(Map mp) {
Iterator it = mp.entrySet().iterator();
while (it.hasNext()) {
Map.Entry pairs = (Map.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
}
}
public static void main(String ... args)throws Exception{
HashMap<Integer,String> mapa=new HashMap<Integer,String>();
if(args.length!=0){
for(int i=0;i<args.length;i++){
mapa.put(i,args[i]);
}
printMap(mapa);
}else{
System.out.println("nada");
}
}
}