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 8978539
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T19:38:19+00:00 2026-06-15T19:38:19+00:00

I see, that in Java you can build strings with MessageFormat and a string

  • 0

I see, that in Java you can build strings with

  • MessageFormat and a string like "You said {0} just now"
  • StringBuffer and a construct like

    StringBuffer mail = new StringBuffer("Dear ");
    mail.append(user.name);
    mail.append(",\nCongratulations!");
    ....
    
  • there may be other good options, string concatenation is not one of them

So, which method should I use? My thoughts are: I have 5-6 standard texts where I have to replace some of the contents dynamically. I think it will be better to have the texts as constants somewhere (class with constants or properties file) and just make the quick replacement when I need it. Otherwise I will have strings in the middle of my source code that may be changed one day, like StringBuffer("Dear ").

Do I have an even better option?

  • 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-06-15T19:38:20+00:00Added an answer on June 15, 2026 at 7:38 pm
        String str = new StringBuffer().append("Hello").append("World").toString();
        System.out.println(str);
    
                //print Hello World 
    
                 it contain into package import java.text.MessageFormat;
                 "When you using Message format"
                  Object[] values = { "123456", "asdfjk" };
    
        String output = MessageFormat.format("Value 1 equals: {0} and Value 2 equals{1}", values);
        System.out.println(output);
        // prints:
        // The value of value 1 is: 123456 The value of value 2 is: asdfjk
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am looking for a fast queue implementation in Java. I see that LinkedList
I am having problems having my Java programs see classes that are packaged in
I'd like to set up a Java application that works as a server, accepting
I need a builder library that can be called from Scala and Java. Easy
When studying Java I learned that Strings were not safe for storing passwords ,
I can see that some methods on the jconsole are disabled. Given below is
I see that this is the same question as Making cmake print commands before
I see that most of big websites are returning javascript objects instead of pure
I see that many people get this error, but their situations all appear a
I see that we cannot use if not exists in the create virtual table

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.