Java - Write code to check if a string is Alphanumeric or Space

Requirements

Write code to check if a string is Alphanumeric or Space

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String str = "book2s.com";
        System.out.println(isAlphanumericSpace(str));
    }//ww  w.  j a va  2s .com

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

        int length = str.length();

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

        return true;
    }
}