MessageFormat.format 字符串模版

字符串模版:把参考{0},{1}的值用数组的值来替换


import java.text.MessageFormat;

// 输出:参数0:参数0的值,参数1:参数1的值,参数2:参数2的值
MessageFormat.format("参数0:{0},参数1:{1},参数2:{2}", new Object[] { "参数0的值", "参数1的值", "参数2的值" })


// 输出:Once upon a time (2011-9-1, around about 下午4:32), there was a humble developer named Geppetto who slaved for 4 days with 21% complete user requirements.
String message = "Once upon a time ({1,date}, around about {1,time,short}), there "
+ "was a humble developer named Geppetto who slaved for "
+ "{0,number,integer} days with {2,number,percent} complete user " + "requirements. ";
Object[] variables = new Object[] { new Integer(4), new Date(), new Double(0.21) };
String output = MessageFormat.format(message, variables);

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值