.NET String.Format equivalent in Java

667 Views Asked by At

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

Is there an equivalent version available in Java?

3

There are 3 best solutions below

0
On

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.

0
On

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

0
On

Try this:

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

see this question and answers