Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Handling nulll while doing equals function

I have two variable and both are strings and I need to compare both variable if it match it should return true otherwise false.
As we know equals function (var1.equals(var2)) does not handle null values and it thows "null pointer exception ".In other words , both variables should have values only then it can work .If I used two equals function (==) function It is not giving expected result as we know the reason.

I am looking for that solution where I can compare null String  with a value
var1="2016-01-03 11:05:07"
var2=null

Labels (2)
1 Reply
Anonymous
Not applicable
Author

use the java ternary operator.

var1 == null ? false : var1.equals(var2)

remember to think about how you want to handle the edge case where both are null as well (if that is indeed a valid scenario).