Con*_*ous 2 java dictionary data-structures
在C#中有一个名为IDictionary的数据结构,它存储一组键值对.Java中有simillar数据结构吗?如果是这样,它叫什么,谁能给我一个如何使用它的例子?
Bob*_*obs 20
最好的方法之一是HashMap:
使用此示例:
HashMap<String, Integer> dicCodeToIndex;
dicCodeToIndex = new HashMap<String, Integer>();
// valuating
dicCodeToIndex.put("123", 1);
dicCodeToIndex.put("456", 2);
// retrieving
int index = dicCodeToIndex.get("123");
// index is 1
Run Code Online (Sandbox Code Playgroud)
看看这个链接:http://docs.oracle.com/javase/6/docs/api/java/util/HashMap.html
| 归档时间: |
|
| 查看次数: |
48988 次 |
| 最近记录: |