In want to assign the value to variable by using filter and find first (to avoid matching rest and saving iteration).
String output = ""
Map<String, Map<String, CustomObj>> finalMap = new LinkedHashMap<>();;
Map<String, CustomObj> isinMap = new HashMap<>();
isinMap.put("REL", new CustomObj("RELIANCE ISIN"));
isinMap.put("AXIS", new CustomObj("AXISBANK ISIN"));
Map<String, CustomObj> cusipMap = new HashMap<>();
cusipMap.put("CREL", new CustomObj("RELIANCE CUSIP"));
cusipMap.put("CAXIS", new CustomObj("AXISBANK CUSIP"));
finalMap.put("ISIN",isinMap);
finalMap.put("CUSIP",cusipMap);
Map<String,String> tradeDetails = new HashMap<>();
tradeDetails.put("ISIN","AXIS");
tradeDetails.put("CUSIP","AXIS2");
finalMap.entrySet().stream().filter(finalMapEntry-> {
String value = tradeDetails.get(finalMapEntry.getKey());
return finalMapEntry.getValue().containsKey(value);
// I want following
//output = finalMapEntry.getValue().get(value).get(); //output should be AXISBANK ISIN
}
).findFirst();
I know findFirst() will return me first entry in Optional but I want the value of inner map key to be assigned to output variable.
IS it possible to do it somehow while streaming and also skipping other iterations if match found on first any nth attempt ?