Sanjay Bharathi:
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()));
Por ejemplo, tengo mapA = {(1,'a'),(2,'b'),(3,'c')}
y mapB = {(5,'a'),(6,'d'),(7,'c')}
comparación de la valueList tanto de los mapas, los valores 'a'
y 'c'
en mapA
ocurrir en mapB
y sus teclas son 5
y 7
resp.
Y por lo tanto se requiere mi O / P:
5
,7
He hecho lo anterior y tengo mi salida requerida. Sin embargo, la complejidad es demasiado terriblemente alto de O (n ^ 2). Los métodos optimizados?
Un ejemplo más simplificado:
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);
Eritrea:
Si consigo este derecho:
Comparando el valueList tanto de los mapas, los valores de 'a' y 'c' en el mapa ocurren en mapB y sus teclas son 5 y 7 respectivamente. Y por lo tanto se requiere mi O / P: 5, 7
¿No es suficiente sólo para filtrar su segundo mapa con la lista # contiene:
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);