Java 数据结构,用于存储受密钥约束的数据

Java 数据结构,用于存储受密钥约束的数据,java,arrays,hashset,Java,Arrays,Hashset,为了存储以下数据,最好使用哪种数据结构 "open" => "11:00", "15:00", "19:00" "close" => "12:00", "17:00","20:00" 我需要能够通过以下方式访问数据: dataStructure.get("open").get(0) => "11:00" 听起来你需要这样的Map map.get(“open”)将返回List,然后您可以使用List方法的get(index) 示例: Map<String, List&

为了存储以下数据,最好使用哪种数据结构

"open" => "11:00", "15:00", "19:00" 
"close" => "12:00", "17:00","20:00"
我需要能够通过以下方式访问数据:

dataStructure.get("open").get(0) => "11:00"

听起来你需要这样的
Map

map.get(“open”)
将返回
List
,然后您可以使用List方法的
get(index)

示例:

Map<String, List<String>> map = new HashMap<>();(java 7)
Map<String, List<String>> map = new HashMap<List<Stirng>>();(pre java 7)
Consider your first input:
map.get("Open").get(0); would yield 11:00
Map Map=newhashmap();(爪哇7)
Map Map=newhashmap();(爪哇7之前)
考虑你的第一个输入:
map.get(“打开”).get(0);将在11:00产生

听起来你需要这样的
Map

map.get(“open”)
将返回
List
,然后您可以使用List方法的
get(index)

示例:

Map<String, List<String>> map = new HashMap<>();(java 7)
Map<String, List<String>> map = new HashMap<List<Stirng>>();(pre java 7)
Consider your first input:
map.get("Open").get(0); would yield 11:00
Map Map=newhashmap();(爪哇7)
Map Map=newhashmap();(爪哇7之前)
考虑你的第一个输入:
map.get(“打开”).get(0);将在11:00产生

基本上,您可以使用带有参数字符串和列表的映射来存储上述内容。。此处列表将存储子值的数量

Map map = new HashMap<String,list>

List list = map.get("key")
list.get(0) // will give the 0th value
Map Map=newhashmap
List=map.get(“键”)
list.get(0)//将给出第0个值

基本上,您可以使用带有参数字符串和列表的映射来存储上述内容。。此处列表将存储子值的数量

Map map = new HashMap<String,list>

List list = map.get("key")
list.get(0) // will give the 0th value
Map Map=newhashmap
List=map.get(“键”)
list.get(0)//将给出第0个值

如果我们使用现有的数据结构,您可以有这样一个映射

  Map<String,List<String>> myMap=new HashMap<String,List<String>>();              

  List<String> openList=new ArrayList<String>();       
  openList.add("11:00");       
  openList.add("15:00");                        
  openList.add("19:00");                 

  List<String> closeList=new ArrayList<String>();                     
  closeList.add("12:00");                     
  closeList.add("17:00");            
  closeList.add("20:00");                       

  myMap.put("open",openList);                       
  myMap.put("close",closeList);                 
Map myMap=newhashmap();
List openList=new ArrayList();
openList.add(“11:00”);
openList.add(“15:00”);
openList.add(“19:00”);
List closeList=new ArrayList();
关闭列表。添加(“12:00”);
关闭列表。添加(“17:00”);
关闭列表。添加(“20:00”);
myMap.put(“打开”,openList);
myMap.put(“关闭”,关闭列表);

如果我们使用现有的数据结构,您可以有这样一个映射

  Map<String,List<String>> myMap=new HashMap<String,List<String>>();              

  List<String> openList=new ArrayList<String>();       
  openList.add("11:00");       
  openList.add("15:00");                        
  openList.add("19:00");                 

  List<String> closeList=new ArrayList<String>();                     
  closeList.add("12:00");                     
  closeList.add("17:00");            
  closeList.add("20:00");                       

  myMap.put("open",openList);                       
  myMap.put("close",closeList);                 
Map myMap=newhashmap();
List openList=new ArrayList();
openList.add(“11:00”);
openList.add(“15:00”);
openList.add(“19:00”);
List closeList=new ArrayList();
关闭列表。添加(“12:00”);
关闭列表。添加(“17:00”);
关闭列表。添加(“20:00”);
myMap.put(“打开”,openList);
myMap.put(“关闭”,关闭列表);

为什么不使用字符串数组并使用open[0]、open[1]等?关闭字符串数组也是如此。

为什么不使用字符串数组并使用open[0]、open[1]等?对于闭合字符串数组也是如此。

为什么不
dataStructure.getOpen(0)
?(使用适当的bean类)为什么不
dataStructure.getOpen(0)
?(使用合适的bean类)Map Map=new HashMap()@klausklausos对不起,我不明白你的意思,你能说得更清楚一点吗我无法编译代码new HashMap();相反,我必须定义HashMapoh,糟糕的是,它只适用于Java7。您必须在java 7Map=new HashMap()@klausklausos之前的构造函数调用中提供类型参数对不起,我不明白您的意思,您能说得更清楚一些吗我无法编译代码new HashMap();相反,我必须定义HashMapoh,糟糕的是,它只适用于Java7。在java 7之前的版本中,必须在构造函数调用中提供类型参数