-Any help will be greatly appreciated! Thanks \"Finally, I\'d like to introduce
ID: 3819727 • Letter: #
Question
-Any help will be greatly appreciated!
Thanks
Explanation / Answer
CODE:
package temp;
import java.util.*;
import java.util.Map.Entry;
class MapCollection{
public static void main(String args[]){
HashMap<String,Integer> schools = new HashMap<String,Integer>();
schools.put("Emmanuel",1919);
schools.put("Northeastern",1898);
schools.put("Wentworth",1904);
System.out.println("Schools");
System.out.print("{");
for(Map.Entry m:schools.entrySet()){
System.out.print(m.getKey()+"="+m.getValue()+ " ");
}
System.out.print("}");
System.out.println(" keys");
System.out.print("[");
for(Map.Entry m:schools.entrySet()){
System.out.print(m.getKey() + " ");
}
System.out.print("]");
System.out.println(" values");
System.out.print("[");
for(Map.Entry m:schools.entrySet()){
System.out.print(m.getValue()+ " ");
}
System.out.print("]");
}
}
OUTPUT:
Schools
{Wentworth=1904 Emmanuel=1919 Northeastern=1898 }
keys
[Wentworth Emmanuel Northeastern ]
values
[1904 1919 1898 ]
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.