Java程序检索HashMap中所有值的集合
首先,创建一个HashMap并添加元素-
HashMap hm = new HashMap();
hm.put("Wallet", new Integer(700));
hm.put("Belt", new Integer(600));
hm.put("Backpack", new Integer(1200));现在,检索所有值-
Collection getValues = hm.values();
System.out.println("\nValues...");
Iterator i = getValues.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}以下是获取HashMap中所有值的集合的示例-
示例
import java.util.*;
public class Demo {
public static void main(String args[]) {
//创建哈希映射
HashMap hm = new HashMap();
hm.put("Wallet", new Integer(700));
hm.put("Belt", new Integer(600));
hm.put("Backpack", new Integer(1200));
System.out.println("Map = "+hm);
Collection getValues = hm.values();
System.out.println("\nValues...");
Iterator i = getValues.iterator();
while (i.hasNext()) {
System.out.println(i.next());
}
}
}输出结果
Map = {Backpack=1200, Belt=600, Wallet=700}
Values...
1200
600
700热门推荐
10 五一公司放假祝福语简短
11 追星女孩的祝福语简短
12 给长辈端午祝福语 简短
13 生日祝福语有诗意简短
14 团圆日祝福语简短
15 中秋商务祝福语简短最新
16 温暖文艺简短祝福语短句
17 男孩上学祝福语简短的
18 入住酒店文案祝福语简短