What classes do you use to make string placeholders work?
String template = "You have %1 tickets for %d",
Brr object = new Brr(template, {new Integer(1), new Date()});
object.print();
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You have two options:
java.util.Formatterprintf-style format strings. This class provides support for layout justification and alignment, common formats for numeric, string, and date/time data, and locale-specific output.java.text.MessageFormat.MessageFormatprovides a means to produce concatenated messages in a language-neutral way. Use this to construct messages displayed for end users.Of the two,
MessageFormatis by far the more powerful. Here’s an example of usingChoiceFormatto handle0,1, and>1case differently:This prints:
The documentation has many more examples.