I'm pretty sure you can't pump all this code into the repl. I did something like entering it line by line, and it did say "created PezDispenser" but the only way to actually make a PezDispenser is with the command "PezDispenser pd = new PezDispenser("name"); For something as complex as a class, I think it's better that you save it as a .java file and work from the command line to compile it and forget about the repl. For example, make a file called PezDispenser.java and have in it: java public class PezDispenser { public static final int MAX_PEZ = 12; private String mCharacterName; private int mPezCount; public PezDispenser(String characterName) { mCharacterName = characterName; mPezCount = 0; } public boolean isEmpty() { return mPezCount == 0; } public void load() { mPezCount = MAX_PEZ; } public String getCharacterName() { return mCharacterName; } public static void main(String[] args) { PezDispenser pd = new PezDispenser("Batman"); System.out.println(pd.isEmpty()); } } Then go to your folder in command line and type "javac PezDispenser.java && java PezDispenser" Answer from r h on teamtreehouse.com
๐ŸŒ
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.
๐ŸŒ
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...
๐ŸŒ
W3Schools
w3schools.com โ€บ java โ€บ ref_string_isempty.asp
Java String isEmpty() Method
Java Examples Java Videos Java Compiler Java Exercises Java Quiz Java Code Challenges Java Server Java Syllabus Java Study Plan Java Interview Q&A Java Certificate ยท โฎ String Methods ยท Find out if a string is empty or not: String myStr1 = "Hello"; String myStr2 = ""; System.out.println(myStr1.isEmpty()); System.out.println(myStr2.isEmpty()); Try it Yourself ยป ยท
๐ŸŒ
InfoQ
infoq.com โ€บ news โ€บ 2026 โ€บ 02 โ€บ java-news-roundup-feb16-2026
Java News Roundup: JDK26-RC2, Payara Platform, Hibernate, Quarkus, Apache Camel, Jakarta EE 12 - InfoQ
6 days ago - Quarkus 3.31.4, the third maintenance release (version 3.31.0 was skipped), provides notable changes such as: a new isEmpty() method, added to the DirectoryPathTree class, to restore the mechanism that was removed in the 3.30 release train for handling empty source sets; and a resolution to a NullPointerException setting the QUARKUS_HTTP_TEST_HOST environmental variable using Gradle 9.3.1.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
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.
๐ŸŒ
GeeksforGeeks
geeksforgeeks.org โ€บ java โ€บ java-string-isempty-method-example
Java String isEmpty() Method with Example - GeeksforGeeks
November 20, 2024 - In Java, the String isEmpty() method checks if a string is empty (length is zero). This method returns true if the string is empty and false otherwise.
๐ŸŒ
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.
๐ŸŒ
Playwright
playwright.dev โ€บ assertions
Assertions | Playwright
Playwright includes test assertions in the form of expect function. To make an assertion, call expect(value) and choose a matcher that reflects the expectation. There are many generic matchers like toEqual, toContain, toBeTruthy that can be used to assert any conditions ยท Playwright also includes ...
๐ŸŒ
Quora
quora.com โ€บ How-do-perform-a-Null-check-for-string-in-Java
How do perform a Null check for string in Java? - Quora
Answer (1 of 7): 4 Ways to check if String is null or empty in Java:- Here are my four solutions for this common problem. Each solution has their pros and cons and a special use case e.g. first solution can only be used from JDK7 on wards, second solution is the fastest way to check string is em...
๐ŸŒ
Scaler
scaler.com โ€บ home โ€บ topics โ€บ isempty() in java
Java String isEmpty - Scaler Topics
January 4, 2024 - The isEmpty() is an inbuilt method of the String class that is used to check whether is the given String is empty or not.
๐ŸŒ
Baeldung
baeldung.com โ€บ home โ€บ java โ€บ java string โ€บ difference between string isempty() and isblank()
Difference Between String isEmpty() and isBlank() | Baeldung
December 2, 2025 - Working with Strings in Java is sometimes confusing because we have many ways to do similar things. In this article, weโ€™ll look at how to validate blank and empty Strings using the isEmpty() and isBlank() methods. Although similar, the two methods are not the same.
๐ŸŒ
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
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.
๐ŸŒ
Vultr Docs
docs.vultr.com โ€บ java โ€บ standard-library โ€บ java โ€บ lang โ€บ String โ€บ isEmpty
Java String isEmpty() - Check If Empty | Vultr Docs
December 17, 2024 - The isEmpty() method in Java is a straightforward and efficient way for checking whether a given string has a length of zero, which means it is an empty string. This method is part of the String class in Java's standard library, making it readily ...