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));
    }/* w  w w  . ja v  a2  s .c  o m*/

    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;
    }
}