Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

string.format equivalence in java

Tags:

java

c#

What is the equivalent Java implementation for string.format?

string s = string.Format("{0} - ({1})", myparam1, myparam2);
like image 345
Daniel Peñalba Avatar asked Feb 27 '26 04:02

Daniel Peñalba


2 Answers

String formatted = String.format("%s - (%s)", myparam1, myparam2);
like image 126
Andreas Dolk Avatar answered Mar 01 '26 19:03

Andreas Dolk


Err... String.format seems like a pretty good candidate. Who would have thought? :-)

There is also MessageFormat.format.

like image 31
JB Nizet Avatar answered Mar 01 '26 17:03

JB Nizet



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!