Reputation: 513
I am trying to make a Hashmap out of a List of Objects[] but I am unable to do so. Below is the code that I have written:
List<Object[]> adjustments = query.getResultList();
Map<Integer, BigDecimal> dpaMap = adjustments.stream().collect(Collectors.toMap(a -> (Integer)a[0], a -> (BigDecimal)a[1]));
I know that only two fields are returning from the query they have the same Type as mentioned in Map, but its not working. Please guide me in this regard.
Thanks In Advance.
Upvotes: 1
Views: 12477
Reputation: 513
So it seems that it was working fine, the column in the DB was returning Float so just had to cast it to BigDecimal
Map<Integer, BigDecimal> dpaMap = adjustments.stream().collect(Collectors.toMap(a -> (Integer)a[0], a -> BigDecimal.valueOf((Float) a[1])));
Thanks a lot people for your help.
Upvotes: 7