Reputation:
I am coming for a help where I have a json object and return a string and few of my strings are return as " "
meaning there is a empty value but there is a space in the quotation. So, what I want to accomplish is I need help to check or implement a way to show null
value instead of " "
. is there a way with my code below? thanks for the help.
Upvotes: 0
Views: 97
Reputation: 10253
A simple method that trims the String (removes leading/trailing whitespace) and then checks if the String
is empty should do the trick:
public String getTrimmedString(String str) {
if (str.trim().isEmpty()) {
return null;
} else {
return str.trim();
}
}
Upvotes: 3