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

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))) + "";
        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值