Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between isEmpty() and zero length

Tags:

java

string

What is the difference between these two methods?

public boolean nameControl(String str) 
{
    if (str.trim().isEmpty()) return false;
    if (str.trim().length() == 0) return false;
    return true;
}

I need find out that str should have at least one character.

like image 532
Sajad Avatar asked Oct 01 '13 21:10

Sajad


2 Answers

There is no real difference between them.

Javadocs for isEmpty()

Returns true if, and only if, length() is 0.

like image 51
rgettman Avatar answered Sep 19 '22 23:09

rgettman


From the Javadoc:

isEmpty

public boolean isEmpty()

Returns true if, and only if, length() is 0.

like image 31
djechlin Avatar answered Sep 21 '22 23:09

djechlin