How can I replace String.isEmpty () in Java?

5

I have the following:

    data = new Json().execute(URL).get();

    System.out.println(data);

    if (!data.isEmpty()) { //erro neste data.isEmpty

I have an error:

  

has an error: Call requires API level 9 (current min is 8): java.lang.String # isEmpty

    
asked by anonymous 13.07.2016 / 05:30

4 answers

7

The easiest way to tell if a string is empty is to check if its size is zero, which is what Java does in isEmpty() method in standard Java:

if (data.length() != 0)
    
13.07.2016 / 05:59
7

Assuming that you are on android:

  • You can use TextUtils.isEmpty (string)
  • String.trim (). equals ("") also works
  • Font

        
    13.07.2016 / 09:44
    1

    Since the date is a String you can do this:

          if(!"".equals(data))      
    
        
    13.07.2016 / 18:20
    0

    It may look like this:

    if (str.equals ("") {     // commands here }

        
    14.07.2016 / 21:44