Android check null or empty string in Android

前端 未结 10 1494
梦如初夏
梦如初夏 2020-12-13 12:07

In my trying AsyncTask I get email address from my server. In onPostExecute() I have to check is email address empty or null

10条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-13 12:22

    All you can do is to call equals() method on empty String literal and pass the object you are testing as shown below :

     String nullString = null;
     String empty = new String();
     boolean test = "".equals(empty); // true 
     System.out.println(test); 
     boolean check = "".equals(nullString); // false 
     System.out.println(check);
    

提交回复
热议问题