I have a Collection
containing some values.
Collection<String> myList = new ArrayList<String>();
myList.add("a");
myList.add("b");
myList.add("c");
I created a Map
which has some values:
Map<String, String> myMap = new HashMap<String, String>();
myMap.put("r", "r");
myMap.put("s","m");
myMap.put("t", "n");
myMap.put("a", "o");
I want to check whether the values in the list are present as a key in the map? The way which I know using Java is to iterate through the list and check if the map contains that particular value using myMap.containsKey(). I want to know if there is anything out there using streams or for-each which saves me either lines of code or an efficient way of doing that! Thanks for thinking through it.
EDIT:
I want to store all the elements present in the myList
which are not there in myMap
. So my output can be a list e.g in this scenario [b,c]
.