title: Android check null or empty string in Android
body: <p>In my trying <code>AsyncTask</code> I get email address from my server. In <code>onPostExecute()</code> I have to check is email address <code>empty</code> or <code>null</code>. I used following code to check it:</p>
  
  <pre><code>if (userEmail != null &amp;&amp; !userEmail.isEmpty()) {
      Toast.makeText(getActivity(), userEmail, Toast.LENGTH_LONG).show();
      UserEmailLabel.setText(userEmail);
  }
  </code></pre>
  
  <p>But in my <code>Toast</code> I see <code>null</code> is printed. My full code:</p>
  
  <pre><code>private class LoadPersonalData extends AsyncTask&lt;String, Void, Void&gt; {
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
      protected Void doInBackground(String... res) {
          List&lt;NameValuePair&gt; params = new ArrayList&lt;NameValuePair&gt;();
          params.add(new BasicNameValuePair("user_id", PrefUserName));
          params.add(new BasicNameValuePair("type", type_data));
          JSONObject json = jsonParser.makeHttpRequest(Url, "POST", params);
          String result = "";
          try {
              result = json.getString("message");
          } catch (JSONException e) {
              e.printStackTrace();
          }
          if (result.equals("success")) {
              try {
                  userEmail = json.getString("email");
              } catch (JSONException e) {
                  // TODO Auto-generated catch block
                  e.printStackTrace();
              }
          }
          return null;
      }
  
      @Override
      protected void onPostExecute(Void result) {
          // TODO Auto-generated method stub
          super.onPostExecute(result);            
          if (userEmail != null &amp;&amp; !userEmail.isEmpty()) {
              Toast.makeText(getActivity(), userEmail, Toast.LENGTH_LONG).show();
              UserEmailLabel.setText(userEmail);
          }
      }
  </code></pre>
  
  <p>How can I check for <code>null</code> and <code>empty</code> string? </p>