Java 占位符

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));	
	}
}

运行结果

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