**Here We have product bean. There is some attributes like productname,tax and ..etc. **
Product product = new Product();
product.setProductName("Laptop");
Product product1 = new Product();
product1.setProductName("Mobile");
List<Product> productList = Arrays.asList(product, product1);
**Created Map of Map<String, List<Map<String, String>>>**
Map<String, List<Map<String, String>>> productCart = new HashMap<String, List<Map<String, String>>>();
List<Map<String, String>> listTax1 = new ArrayList<Map<String, String>>();
List<Map<String, String>> listTax2 = new ArrayList<Map<String, String>>();
Map<String, String> map1 = new HashMap<String, String>();
map1.put("XR", "123");
map1.put("TAX", "234");
map1.put("SURCHARGE", "567");
listTax1.add(map1);
Map<String, String> map2 = new HashMap<String, String>();
map2.put("XR", "1234");
map2.put("TAX", "2345");
map2.put("SURCHARGE", "5678");
listTax2.add(map2);
productCart.put("1", listTax1);
productCart.put("2", listTax2);
<强>// 我想将productCart一一添加到productList中// 将 map 的第一个元素添加到另一个列表的第一个位置,依此类推...将第二个 map 元素添加到列表的第二个位置。
Try with Java 8
最佳答案
是的,你可以使用这个 -
int j=0;
for(int i=0;i<productList.size();i++) {
Product productData= productList.get(i);
List keys =new ArrayList(productCart.keySet());
while(j<=i) {
Object listKeys= keys.get(i);
List<Map<String, String>> pro=productCart.get(listKeys);
for (Map<String, String> map : pro) {
map.forEach((k,v)-> {
//Write Yours Conditions
if(k.equalsIgnoreCase("SURCHARGE")){
}
});
}
j++;
}
}
关于java - 将 map 的第一个元素添加到另一个列表的第一个位置,依此类推...将第二个 map 元素添加到列表的第二个位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61686045/