码迷,mamicode.com
首页 > 编程语言 > 详细

Java中HashMap和TreeMap的区别深入理解

时间:2015-03-01 17:00:13      阅读:389      评论:0      收藏:0      [点我收藏+]

标签:

package com.hephec.Map;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

class HahsMaps
{
public static void main(String[] args)
{
Map<String,String> map=new HashMap<String,String>();
map.put("a","aaa");
map.put("b","bbb");
map.put("c","ccc");
map.put("d","ddd");
Iterator<String> iterator=map.keySet().iterator();
while(iterator.hasNext()){
Object key=iterator.next();
System.out.println("map.get(key) is:"+map.get(key));
}
//定义HashTable,用来测试
Hashtable<String,String> tab=new Hashtable<String,String>();
tab.put("a","aaa");
tab.put("b","bbb");
tab.put("c","ccc");
tab.put("d","ddd");
Iterator<String> iterator_1=tab.keySet().iterator();
while(iterator_1.hasNext()){
Object key=iterator_1.next();
System.out.println("tab.get(key) is:"+tab.get(key));
}
TreeMap<String,String> tmp=new TreeMap<String,String>();
tmp.put("a","aaa");
tmp.put("b","bbb");
tmp.put("c","ccc");
tmp.put("d","ddd");
Iterator<String> iterator_2=tmp.keySet().iterator();
while(iterator_2.hasNext()){
Object key=iterator_2.next();
System.out.println("tmp.get(key) is:"+tmp.get(key));
}
}
}

Java中HashMap和TreeMap的区别深入理解

标签:

原文地址:http://www.cnblogs.com/hephec/p/4307250.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!