Is there a good way to do away with null values in java like in ruby there is:
x = null || "string"
I want to do somthing like this.
String line = reader.readLine() || "";
To prevent null values being passed.
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.
No, there is no null-safe syntax in Java. You should do it manually. Alternatively, you can create or use an utility like commons-lang:
That way you’ll get either the value, or “” if it’s
null