Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

public class Main {
    public static void main(String[] args) {
        String str1 = "Hello";
        String str2 = "";

        // Using the isEmpty() method
        boolean empty1 = str1.isEmpty(); // Assigns false to empty1
        boolean empty2 = str2.isEmpty(); // Assigns true to empty1

        // Using the equals() method
        boolean empty3 = "".equals(str1); // Assigns false to empty3
        boolean empty4 = "".equals(str2); // Assigns true to empty4

        // Comparing length of the string with 0
        boolean empty5 = str1.length() == 0; // Assigns false to empty5
        boolean empty6 = str2.length() == 0; // Assigns true to empty6

    }
}