0
我有以下的Objective-C代码Android SDK中:NSDictionary的字典,objectsForKeys等效
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:names forKeys:dates];
的名字和日期是NSMutableArrays
什么是Java中的等价代码?
感谢
我有以下的Objective-C代码Android SDK中:NSDictionary的字典,objectsForKeys等效
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:names forKeys:dates];
的名字和日期是NSMutableArrays
什么是Java中的等价代码?
感谢
假定日期数组元素是龙(Java的日期)和名称数组元素是字符串。
Map<Long, String> dictionary = new HashMap<Long, String>();
for (int idx = 0; i < dates.length; ++idx) {
dictionary.put(dates[idx], names[idx]);
}
请注意,HashMap不像NSDictionary一样不可变。如果这是不可接受的使用:
Collections.unmodifiableMap(dictionary);
相当于Map
我不知道objective-c,但我会认为相当于一个字典是[地图](http://docs.oracle.com/javase/ tutorial/collections/interfaces/map.html),例如一个HashMap。 – assylias 2012-07-17 08:45:58