我有以下方法来获取特定商店的订单 ID
Map<String, List<String>> extractOrderId (String StoreId) {
// business logic
}
现在我必须对所有商店 id 执行上述方法,所以我已经完成了如下所示的操作,但我想将所有结果存储在名为 HashMap
的不同 resultFinalMap
中
Map<String, List<String>> resultFinalMap;
for (String store: StoreIdList) {
// Storing all the store id as key and
// corresponding value of order ids in the list mapped against the key
}
因此 resultFinalMap
将包含所有不同商店 ID 的键,并且值将是针对商店 ID 提取的不同订单。
答案 0 :(得分:0)
你能创建一个可以存储的 POJO 吗
class Order {
String orderId;
//rest of your order class
}
class Store {
String storeId;
//This will store your orders by id
Map<String, Order> orders;
public Order getOrder(String orderId) {
return orders.get(orderId);
}
}
答案 1 :(得分:0)
既然您已经提到 extractOrderId
返回的地图的键表示 storeId
本身,那么我假设返回的地图只有一个键。那么最好返回一个 List
而不是 Map
extractOrderId
List<String> extractOrderId (String StoreId){
// business logic
}
Map<String, List<String>> resultFinalMap = new HashMap<>();
for (String store: StoreIdList) {
resultFinalMap.put(store, extractOrderId(store));
}