集册 Java实例教程 检查字符串是否是java的原始类型。

检查字符串是否是java的原始类型。

欢马劈雪     最近更新时间:2020-01-02 10:19:05

385
提示:您可在线编辑运行本教程的实例 - 运行实例,去试试!
检查字符串是否是java的原始类型。


//package com.nowjava;


public class Main {
/**来自 
 时 代 J a v a 公 众 号 - nowjava.com**/

    public static void main(String[] argv) {

        String type = "nowjava.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(
展开阅读全文