I have an input stream which I want to use to read specific messages whether it is contained in the map, e.g.: you must consider : Invalid card number.
// this is the line.
I want to check whether this line contains the 'Invalid card number' key of the map.
We have to iterate through the map and checks whether the line contains the message.
String line = "you must consider : Invalid card number.";
for (String key : map) {
if(line.contains(key)) {
throw new Exception(key.value());
}
}
But then we have to iterate through this map for every line of the stream.
Is this a good practice?