Jay Roy
asked on
List to Map
hi experts
In my database table i have data like this
Product type currency
IMAGE-CARTS SamInc. USD
IMAGE-CARTS BCI USD
IMAGE-CARTS RII USD
IMAGE-CARTS POP USD
POP-CARTS SamInc. USD
POP-CARTS BCI USD
POP-CARTS RII USD
POP-CARTS POP USD
BARREL-CARTS SamInc. USD
BARREL-CARTS BCI USD
BARREL-CARTS RII USD
BARREL-CARTS POP USD
I am firing a sql and getting back above data as List<ProductVO> like
List<ProductVO> completeProductList = db.getData();
ProductVO is a bean defined as
my goal is to create a Map<String,List<ProductVO> > which contains data like this
Key value
IMAGE-CARTS List<ProductVO> -- the count of the list must be 4 (for each type and currency)
POP-CARTS List<ProductVO> -- the count of the list must be 4 (for each type and currency)
BARREL-CARTS List<ProductVO> -- the count of the list must be 4 (for each type and currency)
what i am doing is something like this
Map<String,List<ProductVO> > productMap = new HashMap<String,List<Produc tVO>>();
List<ProductVO> tempList = new ArrayList<ProductVO>();
for (ProductVO productData: completeProductList){ //original list from query
String product = productData.getProduct();
tempList.add(productData);
productMap.put(product,tem pList);
}
Now my productMap has 3 keys and each key has value as List<ProductVO> with count 12
Any idea how i can create a Map which contains 3 keys and each key has value as List<ProductVO> with count 4 ?
Thanks very much.
In my database table i have data like this
Product type currency
IMAGE-CARTS SamInc. USD
IMAGE-CARTS BCI USD
IMAGE-CARTS RII USD
IMAGE-CARTS POP USD
POP-CARTS SamInc. USD
POP-CARTS BCI USD
POP-CARTS RII USD
POP-CARTS POP USD
BARREL-CARTS SamInc. USD
BARREL-CARTS BCI USD
BARREL-CARTS RII USD
BARREL-CARTS POP USD
I am firing a sql and getting back above data as List<ProductVO> like
List<ProductVO> completeProductList = db.getData();
ProductVO is a bean defined as
public class ProductVO {
public String product;
public String type;
public String currency;
}
set(); methods
get(); methods
my goal is to create a Map<String,List<ProductVO>
Key value
IMAGE-CARTS List<ProductVO> -- the count of the list must be 4 (for each type and currency)
POP-CARTS List<ProductVO> -- the count of the list must be 4 (for each type and currency)
BARREL-CARTS List<ProductVO> -- the count of the list must be 4 (for each type and currency)
what i am doing is something like this
Map<String,List<ProductVO>
List<ProductVO> tempList = new ArrayList<ProductVO>();
for (ProductVO productData: completeProductList){ //original list from query
String product = productData.getProduct();
tempList.add(productData);
productMap.put(product,tem
}
Now my productMap has 3 keys and each key has value as List<ProductVO> with count 12
Any idea how i can create a Map which contains 3 keys and each key has value as List<ProductVO> with count 4 ?
Thanks very much.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Any help with my next question will be greatly appreciated.
https://www.experts-exchange.com/questions/28543903/HashMap-Converting-long-string-values-to-smaller-codes.html