2
When I try to concatenate one String which, in fact, is null with a string valid (e.g., "a"), get the value nulla. See the example below:
String a = "a";
String b = null;
System.out.println(b + a);
I wanted the output to be just "a". Is there any way to do this without checking if the String is null?
It makes no sense to concatenate with null, the recommended is always to check if any of the variables is null before trying to concatenate.
– user28595
Do you control the value of String b? It’s not interesting to abuse null . Often when something returns null, it should have returned a standard object (in this case, an empty string) or launched an exception.
– Pablo Almeida
Did the answer solve what you were looking to know? Do you think you can accept it now? If not, you need something else to be improved?
– Maniero