首页 > 编程语言 > 详细

Java 占位符

时间:2019-04-25 14:22:11      阅读:268      评论:0      收藏:0      [点我收藏+]

Java的占位符有两种:% 和 {}

String 类对象 只能使用 % 有效。

MessageFormat 类对象 只能使用 {} 有效。

package demo;

import java.text.MessageFormat;


public class doTest {
    public static void main(String[] args) throws Exception {
        System.out.println(String.format("Input = {0} and Output = {1}", 1,2));
        System.out.println(MessageFormat.format("Input = {0} and Output = {1}", 1,2));
        System.out.println();
        System.out.println(String.format("Input = %d and Output = %d", 1,2));
        System.out.println(MessageFormat.format("Input = %d and Output = %d", 1,2));    
    }
}

运行结果

技术分享图片

Java 占位符

原文:https://www.cnblogs.com/lick468/p/10767820.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!