newPropertiesFile.keySet().parallelStream()
.filter(value -> oldPropertiesFile.keySet().parallelStream()
.filter(entry -> oldPropertiesFile.get(entry).toString().equals(newPropertiesFile.get(value).toString()))
.filter(values -> !values.equals(value)).count() > 0)
.collect(Collectors.toMap(entryKey -> (String) entryKey, entryKey -> newPropertiesFile.get(entryKey).toString()));
例如,我有mapA = {(1,'a'),(2,'b'),(3,'c')}
和mapB = {(5,'a'),(6,'d'),(7,'c')}
值列表两个映射的值进行比较'a'
,并'c'
在mapA
在发生mapB
和其键5
和7
RESP。
因此我需要的O / P:
5
,7
我也做了上面,并得到我需要的输出。但复杂性是太他妈高点为O(n ^ 2)。任何优化的方法呢?
更简化的例子:
mapA.keySet().parallelStream()
.filter(v->mapB.keySet().parallelStream()
.filter(e->mapB.get(v).equals(mapA.get(v)))
.filter(v->!v.equals(v)).count()>0)
.forEach(System.out::println);
如果我得到这个权利:
两个映射的值列表进行比较,值“a”和“c”的在地图发生在mapB和他们的密钥是5和7 RESP。因此我所需O / P:5,7
是不是滥竽充数过滤你的第二个地图列表#包含:
Map<Integer,String> mapA = new HashMap<>();
mapA.put(1, "a");
mapA.put(2, "b");
mapA.put(3, "c");
Map<Integer,String> mapB = new HashMap<>();
mapB.put(5, "a");
mapB.put(6, "d");
mapB.put(7, "c");
List<Integer> list = mapB.entrySet().stream()
.filter(e->mapA.containsValue(e.getValue()))
.map(e -> e.getKey())
.collect(Collectors.toList());
System.out.println(list);
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句