I am simply trying to handle null String concatenation with below syntax and both are not compiling - Invalid Assignment Operator and Type Mismacth: can not convert fron null to boolean
String claimId = String.valueOf(VO.getClaimId());
StringBuffer strBuffer = new StringBuffer();
claimId == null?strBuffer.append(""):strBuffer.append(claimId);
OR
String claimId = String.valueOf(VO.getClaimId());
StringBuffer strBuffer = new StringBuffer();
(claimId == null)?strBuffer.append(""):strBuffer.append(claimId);
I simply want to append empty string if claimId String is null and append claimId otherwise.
What works is like,
String tempClaimId = (claimId == null)?"":claimId;
Later I can append tempClaimId to strBuffer
is Assignment expression mandatory here? Can't ternary operator syntax just be used to call methods?
How can I handle calling append with ternary without creating temporary Strings? OR do I just use if-else.