java - How to check String values equal null? -
this question has answer here:
- check whether string not null , not empty 24 answers
i'm new in java programming. have problem when have string variable equals null. when check condition on string error :
exception in thread "main" java.lang.nullpointerexception.
this code :
public class test { static string a=null; public static void main(string[] args) { if(a.equals(null)){ system.out.println("null"); } } }
instead of a.equals(null)
should doing a == null
.
if(a == null) { system.out.println("null"); }
alternatively, can use stringutils
check if string null
or empty doing:
if(stringutils.isempty(a)) { system.out.println("null"); }
Comments
Post a Comment