[英]Convert List<Object[]> Array into Map
I am trying to make a Hashmap out of a List of Objects[] but I am unable to do so. 我正在尝试从Objects []列表中创建一个Hashmap,但是我无法这样做。 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. 我知道只有两个字段从查询中返回,它们具有与Map中提到的类型相同的类型,但是它不起作用。 Please guide me in this regard. 请在这方面指导我。
Thanks In Advance. 提前致谢。
So it seems that it was working fine, the column in the DB was returning Float so just had to cast it to BigDecimal 因此,看起来一切正常,数据库中的列返回Float,因此只需将其强制转换为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. 非常感谢您的帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.