简体   繁体   中英

What is the Java equivalent of Objective-C's NSDictionary?

What is the closest implementation of Objective-C's NSDictionary in Java? To me, it looks like HashMap<String, Object> , but I'm very new to Objective-C.

Thanks

NSDictionary is a class cluster (see the "Class Cluster" section in The Cocoa Fundamentals Guide ), meaning that the actual implementation is hidden from you, the API user. In fact, the Foundation framework will choose the appropriate implementation at run time based on amount of data etc. In addition, NSDictionary can take any id as a key, not just NSString (of course, the -hash of the key object must be constant).

Thus, closest analog is probably Map<Object,Object> .

For practical usage: HashMap<String, Object> would be the way to go for a simple, non-parallel dictionary. However, if you need something that is thread-safe (atomic), you'd have to use HashTable<String, Object> which is thread safe, but - notably - does not accept null as a valid value or key.

我不可否认是一个Android新手,但对我来说, ContentValues似乎是最接近NSDictionary东西。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM