映射以下数据的键值对?
Map a key value pair of the following Data?
Sample Data
我有以下 excel Sheet 并且我想将它绑定到键值对的映射。(使用 JXl 解析数据)
我希望数据结构像
Map<String,Map<String, List<String>>> map
关键是阶段请求集,然后我们有阶段请求和阶段序列的映射。
我已经能够在地图内部制作地图 i:e Map<String, List<String>>
部分
如何将地图添加到地图中,其中它将是某个键的值。
for(int i = 3;i<sheet.getRows();i++){
if(!sheet.getCell(2,i).getContents().isEmpty()){
lastUpdated = sheet.getCell(2,i).getContents();
}
if (!sheet.getCell(3,i).getContents().isEmpty()) {
String content = sheet.getCell(3,i).getContents();
if (map.containsKey(lastUpdated)) {
map.get(lastUpdated).add(content);
} else {
ArrayList<String> temp = new ArrayList<String>();
temp.add(content);
map.put(lastUpdated, temp);
}
}
}
这将为我们提供一个 Map 中的整个 stage req 和 stage seq,该 Map 包含键值对中的 stage 及其 seq 的所有值。
现在如何将此地图绑定到 Stage request Set name Key 。
Java 和 collections 的新手请帮忙。
相信下面就是您所需要的。如果还不够,请通过任何云存储将完整的 excel sheet 作为文件和您的完整源代码共享。
Map<String, Map<String, List<String>>> map = new HashMap<>();
for(int i = 3;i<sheet.getRows();i++){
if(!sheet.getCell(2,i).getContents().isEmpty()){
lastUpdated = sheet.getCell(2,i).getContents();
}
if (!sheet.getCell(3,i).getContents().isEmpty()) {
String content = sheet.getCell(3,i).getContents();
if(!map.containsKey(lastUpdated)){
map.put(lastUpdated, new HashMap<>());
}
if(!map.get(lastUpdated).containsKey(content)){
Map<String, List<String>> rowMap = map.get(lastUpdated);
rowMap.put(content, new ArrayList<>());
map.put(lastUpdated, rowMap);
}
for(Cell c : Arrays.copyOfRange(sheet.getRow(i), 4, sheet.getRow(i).length)){
if(CellType.EMPTY != c.getType()){
map.get(lastUpdated).get(content).add(c.getContents());
}
}
}
}
Sample Data
我有以下 excel Sheet 并且我想将它绑定到键值对的映射。(使用 JXl 解析数据) 我希望数据结构像
Map<String,Map<String, List<String>>> map
关键是阶段请求集,然后我们有阶段请求和阶段序列的映射。
我已经能够在地图内部制作地图 i:e Map<String, List<String>>
部分
如何将地图添加到地图中,其中它将是某个键的值。
for(int i = 3;i<sheet.getRows();i++){
if(!sheet.getCell(2,i).getContents().isEmpty()){
lastUpdated = sheet.getCell(2,i).getContents();
}
if (!sheet.getCell(3,i).getContents().isEmpty()) {
String content = sheet.getCell(3,i).getContents();
if (map.containsKey(lastUpdated)) {
map.get(lastUpdated).add(content);
} else {
ArrayList<String> temp = new ArrayList<String>();
temp.add(content);
map.put(lastUpdated, temp);
}
}
}
这将为我们提供一个 Map 中的整个 stage req 和 stage seq,该 Map 包含键值对中的 stage 及其 seq 的所有值。
现在如何将此地图绑定到 Stage request Set name Key 。
Java 和 collections 的新手请帮忙。
相信下面就是您所需要的。如果还不够,请通过任何云存储将完整的 excel sheet 作为文件和您的完整源代码共享。
Map<String, Map<String, List<String>>> map = new HashMap<>();
for(int i = 3;i<sheet.getRows();i++){
if(!sheet.getCell(2,i).getContents().isEmpty()){
lastUpdated = sheet.getCell(2,i).getContents();
}
if (!sheet.getCell(3,i).getContents().isEmpty()) {
String content = sheet.getCell(3,i).getContents();
if(!map.containsKey(lastUpdated)){
map.put(lastUpdated, new HashMap<>());
}
if(!map.get(lastUpdated).containsKey(content)){
Map<String, List<String>> rowMap = map.get(lastUpdated);
rowMap.put(content, new ArrayList<>());
map.put(lastUpdated, rowMap);
}
for(Cell c : Arrays.copyOfRange(sheet.getRow(i), 4, sheet.getRow(i).length)){
if(CellType.EMPTY != c.getType()){
map.get(lastUpdated).get(content).add(c.getContents());
}
}
}
}