java - How to check String values equal null? -


this question has answer here:

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

Popular posts from this blog

How to check data type in C++? -

javascript - Is getTimezoneOffset() stable during daylight saving transition? -

sql server - SQL Query returns one result, does not return 0 or NULL result -