------------------------------------------------------------- Quietly through .....
Map map=new HashMap(); 这样的定义可以啊。见下面的程序,可以运行的。import java.util.*; public class TestMap { public static void main(String[] args) { Map<String, Integer> m = new HashMap<String, Integer>(); Map<String, Integer> m2 = new HashMap<String, Integer>();
楼主【zhxcoy888】截止到2008-07-09 01:55:26的历史汇总数据(不包括此帖):
发帖的总数量:0 发帖的总分数:0 每贴平均分数:0
回帖的总数量:0 得分贴总数量:0 回帖的得分率:0%
结贴的总数量:0 结贴的总分数:0
无满意结贴数:0 无满意结贴分:0
未结的帖子数:0 未结的总分数:0
结贴的百分比:---------------------结分的百分比:---------------------
无满意结贴率:---------------------无满意结分率:---------------------
如何结贴请参考这里:http://topic.csdn.net/u/20080501/09/ef7ba1b3-6466-49f6-9d92-36fe6d471dd1.html
2.HashMap实现了接口Map,就是说HashMap实现了Map所有的方法。
/ \
/ \
/ \
Set List(有顺序,可以重复)
/ \ \
/ | \
/ HashSet \
/ (不重复,没有特定顺序) / \
/ / \
SortedSet(有顺序) LinkList ArrayList
/
/
TreeSet(不重复,有顺序,类型一样) Map--->HashMap
Map--->TreeMap
Map--->SortedMap
HashMap是Map实现类
Map map=new HashMap();这样是不对的 Map map =new Map(); Map是个接口不能实例化
Quietly through .....
Map map=new HashMap();
这样的定义可以啊。见下面的程序,可以运行的。import java.util.*;
public class TestMap {
public static void main(String[] args) {
Map<String, Integer> m = new HashMap<String, Integer>();
Map<String, Integer> m2 = new HashMap<String, Integer>();
m.put("one", 1);
m.put("two", 2);
m.put("three", 3);
System.out.println( m2.isEmpty()); //true
m2.putAll( m );
System.out.println( m2.isEmpty()); //false
System.out.println( m.put("four", 4));
System.out.println( m.get("one")); //1
m.remove("one");
System.out.println( m.put("two", 20) );
System.out.println( m.containsKey("four")); //true
System.out.println(m.containsValue(2) );
System.out.println( m.size() ); //3
System.out.println( "m2: " + m2 );
if( m.containsKey("two")) {
int i = m.get("two");
System.out.println(i);
}
}
}
/ \
/ \
HashMap实现类 HashTable实现类
HashMap,HashTable都是map的实现类。都是以键值对的形式存储数据。HashiMap没有实现线程安全允许null的键值
Map ma=new HashMap();
ma.pub(key,value);
/ \
/ \
/ \
Set List(有顺序,可以重复)
/ \ \
/ ¦ \
/ HashSet \
/ (不重复,没有特定顺序) / \
/ / \
SortedSet(有顺序) LinkList ArrayList
/
/
TreeSet(不重复,有顺序,类型一样) Map--->HashMap
Map--->TreeMap
Map--->SortedMap
/ \
/ \
/ \
Set List(有顺序,可以重复)
/ \ \
/ ¦ \
/ HashSet \
/ (不重复,没有特定顺序) / \
/ / \
SortedSet(有顺序) LinkList ArrayList
/
/
TreeSet(不重复,有顺序,类型一样) Map--->HashMap 无序
Map--->TreeMap 有序
Map--->SortedMap