java MessageFormat

 
String msg = MessageFormat.format("aa bb {0} cc {1} - {0}", "A", "B");
       System.out.println(msg);
       //aa bb A cc B - A
       
       // 1
       String model = "Hello {0}:  Your name:{0} Age:{1} Address:{2}";
       String[] params = { "Asa", "23", "QiLiHe lz.China" };
       String msg1 = MessageFormat.format(model, params);
       System.out.println(msg1);
       //Hello Asa:  Your name:Asa Age:23 Address:QiLiHe lz.China
       
       // 2
       Object[] params2 = new Object[] { new Date(), new Date(0), new Date() };
       String msg2 = MessageFormat.format("{0,date,short} --- {1,time,medium} --- {2,date,yyyy-MM-dd HH:mm:ss}", params2);
       System.out.println(msg2);
       //11-7-6 --- 8:00:00 --- 2011-07-06 15:40:59
       
       // 3
       Object[] params3 = new Object[] { new Double(0.45), new Double(1234.56) };
       String msg3 = MessageFormat.format("{0,number,percent}  --- {1,number,percent}", params3);
       System.out.println(msg3);
       //45%  --- 123,456%
       
       // 4
       Object[] params4 = new Object[] { new Double(123.45), new Double(1234.56) };
       String msg4 = MessageFormat.format("{0,number,currency} --- {1,number,currency}", params4);
       System.out.println(msg4);
       //¥123.45 --- ¥1,234.56
      
       // 5
       Object[] params5 = new Object[] { new Integer(123), new Integer(1234) };
       String msg5 = MessageFormat.format("{0,number,#} a''s and {1,number,#} b''s", params5);
       System.out.println(msg5);
       //123 a's and 1234 b's

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值