首页
IT
登录
6mi
u
盘
搜
搜 索
IT
HashMap的使用
HashMap的使用
xiaoxiao
2021-03-25
105
import java.util.Collection; import java.util.HashMap; import java.util.Iterator; import java.util.Set;
public class MapDemo {
public static void main(String[] args) {
HashMap<Integer, String> students = new HashMap<>();
students.put(110, "Tom");
students.put(120, "Helen");
students.put(130, "Jane");
Set<Integer> set = students.keySet();
Iterator<Integer> iterator = set.iterator();
while (iterator.hasNext()) {
Integer integer = (Integer) iterator.next();
System.out.println(integer);
}
Collection<String> collection = students.values();
Iterator<String> iterator2 = collection.iterator();
while (iterator2.hasNext()) {
String string = (String) iterator2.next();
System.out.println(string);
}
} }
转载请注明原文地址: https://ju.6miu.com/read-15113.html
技术
最新回复
(
0
)