package com.miller.datastructure.precious;
import java.util.HashMap;
import java.util.Iterator;
/**
* @program: data-structure
* @description: 哈希映射的练习
* @author: Miller.FAN
* @create: 2019-09-25 10:16
**/
public class HashMapTest {
public static void main(String[] args) {
HashMap people =new HashMap();
people.put("miller",32);
people.put("son" ,1);
people.put("niu",30);
HashMap miler =new HashMap(10, (float)0.80);
miler.put("google",89);
miler.put(34,"still");
if(miler.isEmpty()) {
System.out.println("miler is empty" + miler.toString());
}
else {
System.out.println("miler has elements, it has " + miler.size() +" 个元素。");
}
// 遍历方法
Iterator iterator = miler.entrySet().iterator();
while(iterator.hasNext()) {
System.out.println("遍历哈希Map中的元素:" + iterator.next());
}
//利用 forEach遍历
for (Object entity: miler.entrySet()
) {
System.out.println("遍历哈希Map中的元素:" + entity);
}
}
}
网友评论