我想在Java 8中做一个简单的操作。下面是代码
List<Integer> lst = Arrays.asList(1,2,3);
Map<String,List> inner = new HashMap<String,List>();
inner.put("first",lst);
Map<String,Map<String,List>> outer = new HashMap<String,Map<String,List>>();
outer.put("Bigger",inner);
``
What I want to do is , return boolean if all the values in a child map List of Integers satisfy a criteria
I tried to do below but it seems it is not working :
```java
boolean lessThanfiveAll = outer.entrySet().stream().flatMap(e -> e.getValue().entrySet().stream().flatMap(v ->v.getValue().stream().allMatch(e -> e < 5)));
问题出现在
v ->v.getValue().stream().allMatch
allMatch 中的值不被视为整数,我收到编译器错误为 operator < cannot be applied to java.lang.Object
有人可以帮忙吗?
需要使用
flatMap
吗?这行得通吗?
boolean lessThanfiveAll = outer.entrySet().stream().allMatch(e -> e.getValue().entrySet().stream().allMatch(v ->v.getValue().stream().allMatch(e1 -> e1 < 5)));