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 232 views
3 answers 250 views
250 views asked Nov 1, 2020 by avibootz
1 answer 167 views
2 answers 225 views
1 answer 160 views
160 views asked Apr 5, 2021 by avibootz
...