Java - Write code to check if a string is Whitespace

Requirements

Write code to check if a string is Whitespace

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(isWhitespace(str));
    }//from   w  w w  . ja  v  a 2  s.c o  m

    public static boolean isWhitespace(String str) {
        if (str == null) {
            return false;
        }

        int length = str.length();

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

        return true;
    }
}