When I need to display a value that might be null/undefined in Javascript, I usually just write:
console.log(a||"");
Or something similar. Is there a similar way to do this in Java other than:
System.out.println(a!=null?a:"");
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The best you can do besides using the ternary operator is to create a very short method to do the same. Perhaps “ns” for “nullable string”:
Then you can write “System.out.println(ns(a));” However, the ternary operator is clearer – I would only do something like the above if I were doing this all over the place.