In a Java code, I have 11 different strings, some of them (at most 9) can be null. Strings are a part of an object. If none of them is null, I make a string like this :
string1 + "," + string2 + "," + string3 + "," + string4 + "," + string5 + "," + string6 + "(" + string7 + ")" + string8 + string9 + "+" + string10 + string11
If none of them is null, it's okey. But some of them can be null. If I check if each of them is null, code gets really slow and long. How can I generate such a string in an efficient and fast way? Thanks.
nullin your result - there won't be an error or anything like that.String emptyForNull(String s) { return s == null ? "" : s; }