[Java] 字符串格式化

例子:

String s = String.format("%7.2f%6d%-4s", 45.556, 14, "AB");
System.out.println(s);

负号表示左对齐, 显示:_ _ 45.56_ _ _ _ 14AB_ __表示空格

System.out.printf(format, item1, item2, ..., itemk);

等价于:

System.out.print(String.format(format, item1, item2, ..., itemk));

Introduction to Java Programming 10.th, 10.10.7

猜你喜欢

转载自blog.csdn.net/ftell/article/details/82660081