I will send two variables and if the variables are to be checked whether it is null or not. If it is not null then concatenate two Strings with any Delimiter. Else return only one or Empty String.
Do we have any inbuilt method to test or any better way than below?
private String getValue(String valueOne, String valueTwo) {
String value = null;
if(valueOne != null) {
value = valueOne;
}
if(value != null && valueTwo != null) {
value += "-" + valueTwo;
}else if(valueTwo != null) {
value = valueTwo;
}
return value !=null ? value : "";
}
a = "abc" and b = "efg"
OUTPUT: "abc-efg"
a = null and b = "abc"
OUTPUT: "abc";