Java使用占位符输出

printf

String str="World!";
System.out.printf("Hello,%s",str);

%1$s占位符

String str = "World!";
System.out.println(String.format("Hello,%1$s", str));

{}占位符

String str0 = "World!";
String str1 = "I love Java...";
System.out.println(MessageFormat.format("Hello,{0}{1}", str0, str1));
posted @ 2023-01-16 19:04  CharyGao  阅读(21)  评论(0)    收藏  举报