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

  • Home
  • SEARCH
  • 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 6662381
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:23:01+00:00 2026-05-26T02:23:01+00:00

Possible Duplicate: String, StringBuffer, and StringBuilder what is the difference (advantages, disadvantages) between using

  • 0

Possible Duplicate:
String, StringBuffer, and StringBuilder

what is the difference (advantages, disadvantages) between using StringBuilder instead String

StringBuilder text = new StringBuilder();
String cadena = "";
Scanner scanner = new Scanner(new FileInputStream(fFileName), fEncoding);
try {
  while (scanner.hasNextLine()) {
    String line = scanner.nextLine();
    text.append(line);
    cadena += line;
  }
} finally {
  scanner.close();
}    
  • 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-26T02:23:01+00:00Added an answer on May 26, 2026 at 2:23 am

    It’s faster, but isn’t thread-safe.

    You can build strings basically three ways.

    1. by just concatenating strings (“foo” + “bar”) – slowest
    2. by using StringBuffer, which is thread-safe, and faster than #1
    3. by using StringBuilder, which is the fastest of all, but not thread-safe

    Some other distinctions:

    String: Strings are constant; their values cannot be changed after they are created. String buffers support mutable strings. Concatenating strings using the + operator doesn’t modify the Strings involved, it creates a new String that is a combination of the Strings you’re concatenating.

    StringBuffer: A thread-safe, mutable sequence of characters. A string buffer is like a String, but can be modified.

    StringBuilder: A mutable sequence of characters. This class provides an API compatible with StringBuffer, but with no guarantee of synchronization.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Difference between string and StringBuilder in c# What’s the difference between System.String
Possible Duplicate: What is the difference between String.Empty and “” Is equivalent to String.Empty
Possible Duplicate: String vs string in C# What is the difference Between String and
Possible Duplicate: String vs string in C# I know there is no difference between
Possible Duplicate: Differences in string compare methods in C# Is there any difference between
Possible Duplicate: Why to use StringBuffer in Java instead of the string concatenation operator
Possible Duplicate: String vs string in C# I understand there is a difference between
Possible Duplicate: String vs StringBuilder I just revisited some of the books that I
Possible Duplicate: Which collection for storing unique strings? I am currently using a Dictionary<string,
Possible Duplicate: String concatenation vs String Builder. Performance Any difference (performance and memory usage)

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.