on 02-26-2015 11:33 AM
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
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Neil
efficient way is to use methods like isEmpty().
Thanks
Ram
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
9 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.