Java - Write code to Returns true if the given character is a 'standard' character.

Requirements

Write code to Returns true if the given character is a 'standard' character.

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        char character = 'a';
        System.out.println(isSimpleCharacter(character));
    }// w  w  w. j a v a  2 s. co  m

    public static final char[] allowedCharacters = { 'a', 'b', 'c', 'd',
            'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p',
            'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '_', '-',
            '1', '2', '3', '4', '5', '6', '7', '8', '9', '0' };

    /**
     * Returns true if the given character is a 'standard' character. (a-z,
     * A-Z).
     * 
     * @param character
     * @return
     */
    public static boolean isSimpleCharacter(final char character) {
        boolean found = false;
        for (final char element : allowedCharacters) {
            found = found || character == element
                    || character == Character.toUpperCase(element);
        }
        return found;
    }
}

Related Example