How to change the below code to remove if-else and use Java8
List<String> list1;
List<String> list2;
List<String> list3;
String str;
if(list1.contains(str)){
event.getMessage().setInvocationProperty("ABC","ABC1");
}
else if(list2.contains(str)){
event.getMessage().setInvocationProperty("ABC2","ABC3");
}
else if(list3.contains(str)){
event.getMessage().setInvocationProperty("ABC4","ABC5");
}
It is possible to do it without
if-else
, but for this case,if-else
would still be better than using streams.Another solution without using the list as key in
paramMap
: