The method formatted() is undefined for the type String [String.format()]

本文讨论了Java中`formatted()`方法在不同JDK版本(如JDK8和JDK20.0.2)的行为变化,指出从JDK8开始引入Formatter类来替代String.format(),以提高代码可读性。
摘要由CSDN通过智能技术生成

The method formatted() is undefined for the type String  [String.format()] 写代码的人懒到一定程序了已经,然后始作俑者就是写JDK的那般老外,一点阅读性都没有。

JDK8 ----  JDK20.0.2

java.lang.String.class    JDK15

java.util.Formatter.class

        //JDK20
        String username = "zengwenfeng";
        String key = "ac:%s".formatted(username);
        System.out.println(key);//ac:zengwenfeng
        
        //JDK8
        System.out.format("ac:%s", username);
        
        Formatter f = new Formatter();
        System.out.println(f.format("ac:%s", username).toString());
        f.close();

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值