方法定义
public static String format(String format, Object... args)
说明
使用指定的格式字符串和参数返回格式化的字符串。
参数
format - 要格式化的字符
args - 由格式字符串的格式说明符引用的论据。如果有比格式说明符的更多参数,多余的参数会被忽略。参数的数量是可变的,可能是零。
实例
public class Test {
public static void main(String[] args)
{
String str;
// %s 字符串点位符
str= String.format("%s有新的%s需要处理","贵阳仓库","采购入库单");
System.out.println(str);
// %d 整数占位符 %% 百分号占位符
str = String.format("百分之九十:%d%%", 80);
System.out.println(str);
// 换号符 %n
str = String.format("测试到此结束!%n");
System.out.println(str);
}
}