Useful method from Apache Commons:

 org.apache.commons.lang.StringUtils.isBlank(String str)

https://commons.apache.org/proper/commons-lang/javadocs/api-2.6/org/apache/commons/lang/StringUtils.html#isBlank(java.lang.String)

Answer from puczo on Stack Overflow
๐ŸŒ
Oracle
docs.oracle.com โ€บ javase โ€บ 8 โ€บ docs โ€บ api โ€บ java โ€บ lang โ€บ String.html
String (Java Platform SE 8 )
October 20, 2025 - The Java language provides special support for the string concatenation operator ( + ), and for conversion of other objects to strings. String concatenation is implemented through the StringBuilder(or StringBuffer) class and its append method. String conversions are implemented through the ...
๐ŸŒ
Medium
medium.com โ€บ @lp.lok.payu โ€บ isempty-vs-empty-vs-isblank-vs-isnull-12aea580fe4b
isEmpty() vs empty() vs isBlank() vs isNull() | by leela prasad | Medium
February 16, 2025 - The isEmpty operator checks if a string contains no characters and is only whitespace. The isBlank operator checks if a string contains no characters, is only whitespace, and is null.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ properties-isempty-method-in-java-with-examples
Properties isEmpty() method in Java with Examples - GeeksforGeeks
July 11, 2025 - Java Collection ยท Last Updated : 11 Jul, 2025 ยท The isEmpty() method of Properties class is used to check if this Properties object is empty or not. Syntax: public boolean isEmpty() Parameters: This method accepts no parameters Returns: This ...
๐ŸŒ
Stack Abuse
stackabuse.com โ€บ java-check-if-string-is-null-empty-or-blank
Java: Check if String is Null, Empty or Blank
February 28, 2023 - The isEmpty() method returns true or false depending on whether or not our string contains any text.
Find elsewhere
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_string_isempty.asp
Java String isEmpty() Method
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. ... If you want to use W3Schools services as an educational institution, team or enterprise, send ...
๐ŸŒ
Codekru
codekru.com โ€บ home โ€บ java string isempty() method
Java String isEmpty() method - Codekru
May 29, 2022 - java ยท isEmpty() method of the String class will tell you whether the String is empty or not. In this post, we will be learning about the isEmpty() method in detail. Method declaration โ€“ public boolean isEmpty(). What does it do? โ€“ It will tell whether the string is empty or not by checking the length of the String...
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ dictionary-isempty-method-in-java
Dictionary isEmpty() Method in Java - GeeksforGeeks
July 11, 2025 - The isEmpty() method of Dictionary Class checks whether this dictionary has any key-value mappings or not. The function returns TRUE only if there is no entry in this dictionary.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ question about .isempty() and .contains("")
r/learnjava on Reddit: Question about .isEmpty() and .contains("")
July 25, 2023 -

SORRY

I JUST REALISED I MADE A MISTAKE I WANTED TO ASK ABOUT EQUALS("") BUT AT THE SAME TIME I WAS FIGHTING WITH ANOTHER EXCERCISE IN WHICH I HAD TO USE CONTAINS() METHOD AND THIS MESSED UP MY THOUGHTS SORRY FOR WASTING YOUR TIME :/

but still i was able to get some usefull info about contains method so it wasn't as much wasted effort but still sorry

Hi i'm doing(or atleast trying to do) mooc.fi java part 1 course and there in some exercises is required to check for empty input.

So there is my question what is difference between .isEmpty() and .Equals("") because i like to use the first one but in suggested solutions always is used ".Equals("") and i'm wondering is there any rule for using .isEmpty(), maybe it's the matter of optimalization etc. or maybe both are as good

I know it can be stupid question but it's better to ask that and get rid of bad habits in writing code as soon as possible :D

In advance thanks for answers

P.S i hope everything is easy to understand unfortunately my english is still far from good :D

Top answer
1 of 5
2
isEmpty() checks for string length and returns true if it's zero, while contains("") will return true unless the string isn't initialized/null. For checking empty strings or strings containing only whitespace you could also use the method isBlank(). Hope this helps!
2 of 5
1
Please ensure that: Your code is properly formatted as code block - see the sidebar (About on mobile) for instructions You include any and all error messages in full - best also formatted as code block You ask clear questions You demonstrate effort in solving your question/problem - plain posting your assignments is forbidden (and such posts will be removed) as is asking for or giving solutions. If any of the above points is not met, your post can and will be removed without further warning. Code is to be formatted as code block (old reddit/markdown editor: empty line before the code, each code line indented by 4 spaces, new reddit: https://i.imgur.com/EJ7tqek.png ) or linked via an external code hoster, like pastebin.com, github gist, github, bitbucket, gitlab, etc. Please, do not use triple backticks (```) as they will only render properly on new reddit, not on old reddit. Code blocks look like this: public class HelloWorld { public static void main(String[] args) { System.out.println("Hello World!"); } } You do not need to repost unless your post has been removed by a moderator. Just use the edit function of reddit to make sure your post complies with the above. If your post has remained in violation of these rules for a prolonged period of time (at least an hour), a moderator may remove it at their discretion. In this case, they will comment with an explanation on why it has been removed, and you will be required to resubmit the entire post following the proper procedures. To potential helpers Please, do not help if any of the above points are not met, rather report the post. We are trying to improve the quality of posts here. In helping people who can't be bothered to comply with the above points, you are doing the community a disservice. I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.
๐ŸŒ
Medium
anilr9.medium.com โ€บ java-collection-isempty-and-size-usage-7869946a918b
Java Collection isEmpty() and size() usage | by Anil R | Medium
November 7, 2024 - Use isEmpty() when you only need to know if a collection has elements or not. Itโ€™s clearer and can be more efficient. Use size() if you need the actual count of elements, or if youโ€™re performing operations based on the size. Java ยท Collection ยท Isempty ยท Size ยท
๐ŸŒ
BeginnersBook
beginnersbook.com โ€บ 2017 โ€บ 10 โ€บ java-string-isempty-method-with-example
Java String isEmpty() method
June 9, 2024 - Java String isEmpty() method checks whether a String is empty or not. This method returns true if the given string is empty, else it returns false.
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ java-string-isempty-method
Java String isEmpty Method
March 28, 2025 - The Java isEmpty method is one of the String Methods, which is to check whether the user-specified string is Empty or Not.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ checking for empty or blank strings in java
Checking for Empty or Blank Strings in Java | Baeldung
January 8, 2024 - The most convenient way is to use Apache Commons Lang, which provides helpers such as StringUtils.isBlank. If we want to stick to plain Java, we can use a combination of String#trim with either String#isEmpty or String#length.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-string-isempty-method-explained-a731faf082aa
Java String isEmpty() Method Guide | Medium
June 23, 2024 - The isEmpty() method is part of the String class in Java, which is fundamental for handling and manipulating strings. This method provides a simple way to check whether a string is empty, meaning it contains no characters.
๐ŸŒ
Medium
medium.com โ€บ @AlexanderObregon โ€บ java-set-isempty-method-explained-16a8a18f4c63
Java Set.isEmpty() Method Explained | Medium
June 23, 2024 - Understanding the isEmpty() method is vital for efficient Java programming. This method allows you to write cleaner and more efficient code by preventing unnecessary operations on empty sets. For instance, instead of blindly iterating over a set or performing complex operations, you can first check if the set is empty and decide your course of action based on the result.