Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
In a simple tMap mapping, I need to convert a string to boolean. The data is all 0s/1s and I am using Boolean.valueOf(variable) and all I am seeing is 'false' being returned. What am I doing wrong?
I've validated everything using tLogRow on both the sides of the tMap. The input clearly prints all the 0s and 1s. The output of tMap is all false.
According to java docs Boolean.valueOf(String s):
Returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".
Since your input of "0" or "1" is not "true" All will be evaluated to false
try this instead
row1.data.equals("1") ? true : false
According to java docs Boolean.valueOf(String s):
Returns a Boolean with a value represented by the specified string. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string "true".
Since your input of "0" or "1" is not "true" All will be evaluated to false
try this instead
row1.data.equals("1") ? true : false
Yeah I figured that. Using "1".equals(column name). Slightly shorter to type.
quick tip with the .equals() and .equalsIgnoreCase() methods: If you write them "backwards" by calling the method from your string constant, you'll avoid nullpointer exceptions when your input data is null.
this will not throw a NPE when row1.data is null
"1".equals(row1.data) ? true : false
Hi All,
I wanted to convert data type string to boolean. input data is T/F.
getting an error: Cannot convert "F" to Boolean