if ((A!= null || A!= "") && (B!= null || B!= "")
&& (C!= null || C!= "")elseif...elseif...elseif...
How we can do this without if else condition or in minimum code ??
if ((A!= null || A!= "") && (B!= null || B!= "")
&& (C!= null || C!= "")elseif...elseif...elseif...
How we can do this without if else condition or in minimum code ??
Say you have a List<String>
and any number could be null
or empty you can do
List<String> values = ...
List<String> good = values.stream()
.filter(s -> s != null && !s.isEmpty())
.collect(Collectors.toList());
Instead of having lots of variables, you are better off having an appropriate collection.
I would group all the strings in a stream and then apply the same logic to each element:
Stream<String> strings = Stream.of(a, b, c, ...);
if (strings.allMatch(s -> s != null || s != "")) {
//
}
Note: I've changed variable names to a, b, c, etc., since Java conventions establish that variable names should be lowerCamelCase.