java java键/值对对象,不是数组/映射
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10723186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java key/value pair object, that isn't an array/map
提问by CQM
I want a key value pair object. Just two strings
我想要一个键值对对象。只有两根弦
so Object<String, String>
所以 Object<String, String>
is there an existing object in java to facilitate this before I reinvent the wheel?
在我重新发明轮子之前,java 中是否有一个现有的对象来促进这一点?
The only reason I didn't immediately gravitate to Hash/Map this time is because that one object is made to store multiple key/value pairs. Is there one designed to hold just a single key/value pair, that I can turn into an array if I feel inclined to do so?
这次我没有立即被 Hash/Map 吸引的唯一原因是因为该对象用于存储多个键/值对。是否有一个设计为只保存一个键/值对,如果我愿意的话,我可以把它变成一个数组?
回答by Attila
You will need to create your own. This is done (AFAIK) to facilitate a better semantic meaning from the class name, than a general Pair<>
or KeyValuePair<>
would
您将需要创建自己的。这样做 (AFAIK) 是为了从类名中获得更好的语义,而不是一般的Pair<>
或KeyValuePair<>
将
回答by bpgergo
回答by Jared Westbrook
You could try a Linked-List of Pair.
您可以尝试使用链表对。
Basic structure
基本结构
(0) --> <-- ((0)(Pair < 1, "Stud" >)(2)) --> <-- (1)(Pair < 2, "Sexy" >)(3)....
(0) --> <-- ((0)(Pair < 1, "Stud" >)(2)) --> <-- (1)(Pair < 2, "Sexy" >)(3). ...
Where each Node in the structure is (prev. < K,V >, this < K,V >, next < K,V >) Allows for duplicated keys however...
结构中的每个节点在哪里 (prev. < K,V >, this < K,V >, next < K,V >) 允许重复的键但是...
Head & Tail are null if the Linked-List is empty;
如果链表为空,则 Head & Tail 为 null;