Java output formatting(Java 输出格式)
问题描述
我想知道 Java 是否有某种类来帮助输出格式化.我知道在 C++ 中,在 iomanip 中有一个方法调用 setw.我想知道Java是否有类似的东西.
I was wondering if Java has some sort of class to help on output formatting. I know in C++, in iomanip, there is a method call setw. I was wondering if Java has something similar to this.
推荐答案
看看java.util.Formatter.
String.format() 提供了一个方便的包装器.
String.format() provides a convenient wrapper.
例如(根据链接上的示例修改):
For example (modified from an example on the link):
String s = String.format("e = %+10.4f", Math.E);
它超越了 C 的 ?printf 格式.例如,它支持可选的语言环境,格式符号可以通过显式索引而不是隐式与参数关联.
It goes beyond C's ?printf formats. For example, it supports an optional locale, and format symbols can be associated with an argument by explicit index rather than implicit.
修复了上面的链接.
这篇关于Java 输出格式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:Java 输出格式


- 如何使用WebFilter实现授权头检查 2022-01-01
- 从 finally 块返回时 Java 的奇怪行为 2022-01-01
- Java包名称中单词分隔符的约定是什么? 2022-01-01
- Safepoint+stats 日志,输出 JDK12 中没有 vmop 操作 2022-01-01
- Eclipse 插件更新错误日志在哪里? 2022-01-01
- 将log4j 1.2配置转换为log4j 2配置 2022-01-01
- C++ 和 Java 进程之间的共享内存 2022-01-01
- Spring Boot连接到使用仲裁器运行的MongoDB副本集 2022-01-01
- value & 是什么意思?0xff 在 Java 中做什么? 2022-01-01
- Jersey REST 客户端:发布多部分数据 2022-01-01