Java - Write code to check if a string has Blank space

Requirements

Write code to check if a string has Blank space

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(hasBlank(str));
    }/*from w  w  w  .j av  a  2 s . co m*/

    public static boolean hasBlank(String... str) {
        if (str == null) {
            return true;
        }
        for (int i = 0; i < str.length; i++) {
            if (isBlank(str[i])) {
                return true;
            }
        }
        return false;
    }

    public static boolean isBlank(String str) {
        int length;

        if ((str == null) || ((length = str.length()) == 0)) {
            return true;
        }

        for (int i = 0; i < length; i++) {
            if (!Character.isWhitespace(str.charAt(i))) {
                return false;
            }
        }

        return true;
    }
}

Related Exercise