2013-05-16 19 views

回答

6

PHP的关联数组的等价物是Java中的Map。既与最常用的实施是HashMap共享键值对实施

Map<String, Integer> map = new HashMap<>(); 
map.put("foo", 54); 

System.out.println(map.get("foo")); // displays 54 

其它实现存在诸如LinkedHashMap其保留插入顺序和TreeMap其是根据其键的natural ordering排序。

2

使用map实施,做到这一点:

Map<String, Integer> m = new HashMap<String, Integer>(); 
m.put("foo", 54); 
m.get("foo"); // will yield 54