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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T05:19:08+00:00 2026-05-16T05:19:08+00:00

When developing in Java a couple of years ago I learned that it is

  • 0

When developing in Java a couple of years ago I learned that it is better to append a char if I had a single character instead of a string with one character because the VM would not have to do any lookup on the string value in its internal string pool.

string stringappend = "Hello " + name + "."; 
string charappend = "Hello " + name + '.'; // better?

When I started programming in C# I never thought of the chance that it would be the same with its “VM”. I came across C# String Theory—String intern pool that states that C# also has an internal string pool (I guess it would be weird if it didn’t) so my question is,

are there actually any benefits in appending a char instead of a string when concatenating to a string regarding C# or is it just jibberish?

Edit: Please disregard StringBuilder and string.Format, I am more interested in why I would replace “.” with ‘.’ in code. I am well aware of those classes and functions.

  • 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-16T05:19:09+00:00Added an answer on May 16, 2026 at 5:19 am

    If given a choice, I would pass a string rather than a char when calling System.String.Concat or the (equivalent) + operator.

    The only overloads that I see for System.String.Concat all take either strings or objects. Since a char isn’t a string, the object version would be chosen. This would cause the char to be boxed. After Concat verifies that the object reference isn’t null, it would then call object.ToString on the char. It would then generate the dreaded single-character string that was being avoided in the first place, before creating the new concatinated string.

    So I don’t see how passing a char is going to gain anything.

    Maybe someone wants to look at the Concat operation in Reflector to see if there is special handling for char?

    UPDATE

    As I thought, this test confirms that char is slightly slower.

    using System;
    using System.Diagnostics;
    
    namespace ConsoleApplication19
    {
        class Program
        {
            static void Main(string[] args)
            {
                TimeSpan throwAwayString = StringTest(100);
                TimeSpan throwAwayChar = CharTest(100);
                TimeSpan realStringTime = StringTest(10000000);
                TimeSpan realCharTime = CharTest(10000000);
                Console.WriteLine("string time: {0}", realStringTime);
                Console.WriteLine("char time: {0}", realCharTime);
                Console.ReadLine();
            }
    
            private static TimeSpan StringTest(int attemptCount)
            {
                Stopwatch sw = new Stopwatch();
                string concatResult = string.Empty;
                sw.Start();
                for (int counter = 0; counter < attemptCount; counter++)
                    concatResult = counter.ToString() + ".";
                sw.Stop();
                return sw.Elapsed;
            }
    
            private static TimeSpan CharTest(int attemptCount)
            {
                Stopwatch sw = new Stopwatch();
                string concatResult = string.Empty;
                sw.Start();
                for (int counter = 0; counter < attemptCount; counter++)
                    concatResult = counter.ToString() + '.';
                sw.Stop();
                return sw.Elapsed;
            }
        }
    }
    

    Results:

    string time: 00:00:02.1878399
    char time: 00:00:02.6671247
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Developing Java, you have always learned that its best to create an ArrayList by
I am currently developing a Java web application that exposes a web service interface.
I'm developing a Java application that uses java.util.logging for its logging needs. This application
I'm developing a Java Web Application that runs a series of financial calculations for
My team is developing Java code in a couple different IDEs, with differing numbers
i am developing a java swing application that doesn't fit the normal application profile.
I am developing a java mobile application. Its purpose is that, when installed, it
I am developing a Java application using Google App Engine that depends on a
I'm developing a java application that uses some jni calls. I have on C
I'm developing a Mac App in Java that logs into any one of our

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.