Java 占位符
阿新 • • 發佈:2019-04-25
ring 使用 java tex ava %d alt port 類對象
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 占位符