I'm working on a school project in eclipse, and when I try and use the isEmpty()
method on a String
, Eclipse shows up the following error:
The method isEmpty() is undefined for the type String
I've run the Java updates, but am still getting it. Is any reason why this method would be undefined?
isEmpty() String method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false. The isEmpty() method of String class is included in java string since JDK 1.6. In other words, you can say that this method returns true if the length of the string is 0.
The isEmpty() method checks whether a string is empty or not. This method returns true if the string is empty (length() is 0), and false if not.
This example uses the IsEmpty function to determine whether a variable has been initialized. MyCheck = IsEmpty(MyVar) ' Returns True. MyVar = Null ' Assign Null. MyCheck = IsEmpty(MyVar) ' Returns False.
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.
(source: lumidant.com)
If you're not on Java 6, String.length() == 0 will return the same result as String.isEmpty().
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With