I would like to use the following compact way to build a String:
String attributes = null;
for (Map.Entry<String, String> kvp : attrs.entrySet())
attributes += (kvp.getKey() + "='" + kvp.getValue() +"' ");
but the result is a String which reads: nullattr1='val1' attr2='val2' attr3='val3'. I presume that this is happening as a result of performing a += operation on a String whose current value is null. Is there no compact way to do this without having to check if attributes is null each time through the loop?
Do this for initializing the
Stringat the beginning of the code: