How to check if a string is empty in Java

1 Answer

0 votes
public class MyClass {
    public static boolean isEmpty(String s) {
        return s.length() == 0; 
    }
    public static void main(String args[]) {
        String s1 = "";
        String s2 = "java";

        System.out.println(isEmpty(s1));
        System.out.println(isEmpty(s2));
    }
}


/*
run:

true
false

*/

 



answered Jun 29, 2019 by avibootz

Related questions

1 answer 330 views
3 answers 388 views
388 views asked Nov 1, 2020 by avibootz
1 answer 258 views
2 answers 359 views
1 answer 238 views
238 views asked Apr 5, 2021 by avibootz
...