Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6063045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T09:07:14+00:00 2026-05-23T09:07:14+00:00

Primitive question, but how do I format strings like this: Step {1} of {2}

  • 0

Primitive question, but how do I format strings like this:

“Step {1} of {2}”

by substituting variables using Java? In C# it’s easy.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T09:07:15+00:00Added an answer on May 23, 2026 at 9:07 am

    In addition to String.format, also take a look java.text.MessageFormat. The format less terse and a bit closer to the C# example you’ve provided and you can use it for parsing as well.

    For example:

    int someNumber = 42;
    String someString = "foobar";
    Object[] args = {new Long(someNumber), someString};
    MessageFormat fmt = new MessageFormat("String is \"{1}\", number is {0}.");
    System.out.println(fmt.format(args));
    

    A nicer example takes advantage of the varargs and autoboxing improvements in Java 1.5 and turns the above into a one-liner:

    MessageFormat.format("String is \"{1}\", number is {0}.", 42, "foobar");
    

    MessageFormat is a little bit nicer for doing i18nized plurals with the choice modifier. To specify a message that correctly uses the singular form when a variable is 1 and plural otherwise, you can do something like this:

    String formatString = "there were {0} {0,choice,0#objects|1#object|1<objects}";
    MessageFormat fmt = new MessageFormat(formatString);
    fmt.format(new Object[] { new Long(numberOfObjects) });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This may be a bit of an easy, headdesk sort of question, but my
(Sorry if this sounds like a rant, but it's a real question and I'd
I'm aware of this question here but I have a slightly different question. If
Very primitive question but I am stuck (I guess being newbie). I have a
This may sound a bit provocative but it actually is a real question. Feel
This is a past exam question and I was wondering what a primitive type
This question is related to this one but I think should be asked separately.
Hi, I have a linq to sql question like this : tmpAdList1 = (from
I know the question already has a solution (eg. this question ) but I
I am not sure how appropriate is this question, but - I am curious

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.