判断char类型字符是否为空字符


        if('\0' == b){
            System.out.println("b为空字符");
        }else{
            System.out.println("判断不为空");
        }
        String str = String.valueOf(b);

        if ("\0".equals(str)) {
            System.out.println("为空");
        } else {
            System.out.println("不为空" + str);
        }

        if (str.length() == 1) {
            System.out.println("为空");
        } else {
            System.out.println("不为空" + str);
        }

注:String类型的空格哪怕用 char[] haveNull = str.toCharArray();转换,char数组是变成了空格的字符进行存储,而非'\0'的形式!


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM