笔记记录------随笔记录(一)

public class Test {
    
    
    public static void main(String[] args) {
    
    
        String test;
        boolean empty = isEmpty(test);


    }

    private boolean isEmpty(Object o) {
    
    
        return org.springframework.util.StringUtils.isEmpty(o);
    }
}

适用于需要调用的类,会调用出全部路径的时候,自定义方法,直接调用,使代码看起来比较清晰美观。

日期格式转换中的format.setLenient方法:
在format.setLenient(false) 不开启的情况下开启format.setLenient(false) 严格控制日期转换,不常规的格式就变成非法的了format.setLenient(true) 功能关闭

判断字符串是不是数字方法Character.isDigit()

 public static void main(String[] arge) {
    
    
        String str = "0.566";
        for (int i = 0; i < str.length(); i++) {
    
    
            System.out.println(str.charAt(i));
            if (Character.isDigit(str.charAt(i))) {
    
    //其中Character.isDigit方法:确定或判断指定字符是否是一个数字。
                System.out.println("是数字");
                System.out.println("第一个数字为:"+str.charAt(0));
            }
            else {
    
    	System.out.println("不是数字");}
        }
    }

// 或者使用这种方法字符串转数组的方法进行判断,都一样
// char[] number = certificateNo.toCharArray();
// flag = Character.isDigit(number[x]);

旧的身份证号码有15位,新的身份证号码有18位

// certificateNo 身份证号 String格式
if (flag && certificateNo.length() == 15) {
    
    
            birthday = "19" + certificateNo.substring(6, 8) + "-"
                    + certificateNo.substring(8, 10) + "-"
                    + certificateNo.substring(10, 12);
            // 106001	男106002	女
            sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 3, certificateNo.length())) % 2 == 0 ? "106002" : "106001";
            age = (year - Integer.parseInt("19" + certificateNo.substring(6, 8))) + "";
        } else if (flag && certificateNo.length() == 18) {
    
    
            birthday = certificateNo.substring(6, 10) + "-"
                    + certificateNo.substring(10, 12) + "-"
                    + certificateNo.substring(12, 14);
            sexCode = Integer.parseInt(certificateNo.substring(certificateNo.length() - 4, certificateNo.length() - 1)) % 2 == 0 ? "106002" : "106001";
            age = (year - Integer.parseInt(certificateNo.substring(6, 10))) + "";
        }

おすすめ

転載: blog.csdn.net/cz_chen_zhuo/article/details/109442233