2

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

Is there an equivalent version available in Java?

David Fullerton
  • 3,224
  • 27
  • 38
mlzboy
  • 14,343
  • 23
  • 76
  • 97
  • 1
    Did you search for this? Check [this](http://stackoverflow.com/questions/513600/should-i-use-javas-string-format-if-performance-is-important) might help you. – Amar Palsapure Feb 02 '12 at 06:04

3 Answers3

1

Try this:

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

see this question and answers

Community
  • 1
  • 1
afruzan
  • 1,454
  • 19
  • 20
1

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

Amar Palsapure
  • 9,590
  • 1
  • 27
  • 46
proko
  • 1,180
  • 1
  • 7
  • 14
-1

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.

Nadir Muzaffar
  • 4,772
  • 2
  • 32
  • 48