How to do string formatting with placeholders in Java (like in Python)?

前端 未结 5 1010
南笙
南笙 2020-12-08 09:55

I am new to Java and am from Python. In Python we do string formatting like this:

>>> x = 4
>>> y = 5
>>> print(\"{0} + {1} = {2}\         


        
5条回答
  •  离开以前
    2020-12-08 10:21

    Slf4j has MessageFormatter.format() that accepts {} without the argument number, just like Python. Slf4j is a popular logging framework, but you don't have to use it for logging to use MessageFormatter.

提交回复
热议问题