**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元素添加到列表的第二个位置
试用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++;
}
}