[英]What is the Java equivalent of Objective-C's NSDictionary?
What is the closest implementation of Objective-C's NSDictionary
in Java? 在Java中,Objective-C的NSDictionary
最接近的实现是什么? To me, it looks like HashMap<String, Object>
, but I'm very new to Objective-C. 对我来说,它看起来像HashMap<String, Object>
,但我对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. NSDictionary
是一个类集群(请参阅“ Cocoa基础指南 ”中的“类集群”部分),这意味着实际的实现对您(API用户)是隐藏的。 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). 实际上,Foundation框架将根据数据量等在运行时选择适当的实现。此外, NSDictionary
可以将任何id
作为键,而不仅仅是NSString
(当然,键对象的-hash
必须是常量)。
Thus, closest analog is probably Map<Object,Object>
. 因此,最接近的模拟可能是Map<Object,Object>
。
For practical usage: HashMap<String, Object>
would be the way to go for a simple, non-parallel dictionary. 对于实际用法: HashMap<String, Object>
将是一种简单的非并行字典。 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. 但是,如果你需要线程安全(原子)的东西,你必须使用线程安全的HashTable<String, Object>
,但是 - 特别是 - 不接受null作为有效值或密钥。
我不可否认是一个Android新手,但对我来说, ContentValues似乎是最接近NSDictionary
东西。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.