简体   繁体   中英

.NET String.Format equivalent in Java

I know there is a function string.Format() in .NET

Is there an equivalent version available in Java?

Try this:

String format = "Test: {0}, {1}"
System.out.println(MessageFormat.format(format, "Text1", "Text2"))

see this question and answers

Yes, there is also String.format() which supports output ala C printf() since Java 1.5.

String.format(String format, Object... args) 
System.out.format() // alternativ
System.out.printf() // alternativ

javadoc

Perhaps not exactly equal but Java does have String.format which provides very similar functionality. You'll find that Java and C# are very similar.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM