检查字符串是否是Java的基本类型

public class Main {
    public static void main(String[] argv) {
        String type = "java.com";
        System.out.println(isPrimitive(type));
    }

    /**
     * Checks whether a string is a primitive type of java.
     * 
     * @param type the type to be checked whether it is a primitive.
     * @return a boolean denoting whether the given type is a primitive ({@code true}), or not ({@code false}).
     */
    public static boolean isPrimitive(String type) {
        return (type.equals("boolean") || type.equals("char")
                || type.equals("double") || type.equals("float")
                || type.equals("integer") || type.equals("string") || type
                    .equals("boolean"))
                || (type.equals("Boolean") || type.equals("Char")
                        || type.equals("Double") || type.equals("Float")
                        || type.equals("Integer") || type.equals("String")
                        || type.equals("Boolean") || type.equals("int")
                        || type.equals("long") || type.equals("Int") || type
                            .equals("Long"));
    }
}

你可能感兴趣的:(检查字符串是否是Java的基本类型)