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));
    }/*  ww w  . j  ava2s .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;
    }
}