Java isEmpty() undefined for String?

String.isEmpty() was added in Java 6. In earlier versions you can use StringUtils.isEmpty(String) from Apache's commons-lang library.

To configure Eclipse to use the 1.6 JRE, go to Window->Preferences->Java->Installed JREs. If you haven't already got JAva 1.6 configured, select Add...,browse to your 1.6 installation and add it.

installed JREs screenshot

configure JREs screenshot
(source: lumidant.com)


String.isEmpty() was introduced in Java release 1.6. You might want to check what JDK version you're using for your project. (I don't know much about Eclipse myself, but it should be somewhere in the project settings.)


If you're not on Java 6, String.length() == 0 will return the same result as String.isEmpty().