[英]how do i write this as a list<map<string, string> structure in java
how do i write this as a list structure in java 我如何在java中将其写为列表结构
In this case i want the structure to be like this, Where options is also a key in another 在这种情况下,我希望结构是这样的,其中选项也是另一个的关键
hashmap called styles hashmap称为样式
options[{"value":"0","label":"zero"},{"value":"1","label":"one"},
{"value":"2","label":"two"}]
Here if i want to access options[1].value should give me 1 and options[2].label should give me two. 在这里,如果我想访问选项[1] .value应该给我1和选项[2] .label应该给我两个。
How can i achieve this with 我怎样才能实现这一目标
LIst<Map<string><string[]>>?
Also Can i pass "options" array as one of the keys in my hash map 我也可以将“options”数组作为哈希映射中的一个键
protected Map<String, String[]> getValueProperties(int view, Field field) {
Map<String, String> properties = new HashMap<String,String[]>();
properties.put("options", []);
return properties
}
I am new to handling data in this format, any pointers will be good 我是处理这种格式的数据的新手,任何指针都会很好
使用此数据结构:
List< Map<String, String> >
I think this can do: 我认为这可以做到:
List<Map<String,String>> options = new ArrayList<Map<String,String>>();
and populate as : 并填充为:
Map<String, String> option1 = new HashMap<String, String>();
option1.put("value", "0");
option1.put("level", "zero");
options.add(option1);
Map<String, String> option2 = new HashMap<String, String>();
option2.put("value", "1");
option2.put("level", "one");
options.add(option2);
Map<String, String> option3 = new HashMap<String, String>();
option3.put("value", "2");
option3.put("level", "two");
options.add(option3);
EDIT: You can populate the list in a loop as below: 编辑:您可以在循环中填充列表,如下所示:
List<Map<String,String>> options = new ArrayList<Map<String,String>>();
String[] levels = {"zero", "one", "two"};
for(int indx = 0; indx <levels.length; indx++){
Map<String, String> option = new HashMap<String, String>();
option.put("value", String.valueOf(indx));
option.put("level", levels[indx]);
options.add(option);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.