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

前端 未结 5 1015
南笙
南笙 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:37

    The MessageFormat class looks like what you're after.

    System.out.println(MessageFormat.format("{0} + {1} = {2}", x, y, x + y));
    

提交回复
热议问题