cancel
Showing results for 
Search instead for 
Did you mean: 

String Comparison UDF

neilpadilla
Participant
0 Kudos

Hi Guys!

Do we have best practices done in creating a UDF?

I have a UDF to compare a string.

Which is better?

UDF 1:
if (var1 != null && var1 != "") vs if (var1 != null && !var1.isEmpty()

UDF 2:
if (var1 == STRING)) vs if (var1.equals("STRING"))

Thanks,
Neil

Accepted Solutions (1)

Accepted Solutions (1)

engswee
Active Contributor
0 Kudos

Hi Neil

String values cannot be compared with ==. ==/!= is used to compare object references.

For comparing String values, you need to use the equals() method or isEmpty() method.

Rgds

Eng Swee

neilpadilla
Participant
0 Kudos

Thanks Eng Swee!

Answers (2)

Answers (2)

Former Member
0 Kudos

Hi Neil

efficient way is to use methods like isEmpty().

Thanks

Ram

0 Kudos

Hi Neil,

For UDF 1 set , option 1 would be more efficient and for UDF 2 set , both the expressions would work in more or less similar way.

Hope this is helpful !!!

Cheers,

Abhi