Java Method Varargs String Array with all empty values

Description

Java Method Varargs String Array with all empty values


//package com.demo2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String values = "";
        System.out.println(allEmpty(values));
    }/*from   www  .j  a v a  2s  . c o  m*/

    public static boolean allEmpty(String... values) {
        if (values == null) {
            return true;
        }
        for (String v : values) {
            if (!isEmpty(v)) {
                return false;
            }
        }
        return true;
    }

    public static boolean isEmpty(String input) {
        return input == null || "".equals(input);
    }
}

//package com.demo2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        String[] strings = new String[] { "CSS", "HTML", "Java", null, "demo2s.com", "Javascript 123" };
        System.out.println(allEmpty(strings));
    }/* ww w  .  j a  v a  2s .co m*/

    private static boolean allEmpty(String[] strings) {
        for (String string : strings) {
            if (!string.equals("")) {
                return false;
            }
        }

        return true;
    }
}



PreviousNext

Related