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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T08:11:55+00:00 2026-05-28T08:11:55+00:00

Possible Duplicates: Java String declaration Java Strings: String s = new String(silly); What is

  • 0

Possible Duplicates:
Java String declaration
Java Strings: “String s = new String(”silly“);”
What is the purpose of the expression “new String(…)” in Java?

Whats is the difference between

String a = new String("SomeValue");

and

String a = "SomeValue";

What is the difference and Which one is better and why ?

Thanks.

  • 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-28T08:11:55+00:00Added an answer on May 28, 2026 at 8:11 am

    Unless you have a unusual, specific need and use case, always use the 2nd version, without the new.

    Edited in response to @Ynwa

    If you specifically need a String that you know is unique, and you will be comparing with == (which is also unusual), then use the 1st case. For example, it you have some Queue of Strings, and you need a specific String to mean “all done”. Now, conceivably, you could use null or some weird String of Armenian characters, but maybe null is legal for your logic, and what if your software eventually gets used in Armenia? The clean way is

        public final static String TERMINATOR = new String("Terminator");  // actual text doesn't matter ... 
       // then, some loop taking from the Queue 
       while (keepGoing) {    
          String s = myQueue.take();    
          if (s == TERMINATOR) 
             keepGoing = false;    
         else   
           // normal processing of s 
       }
    

    If the client puts “Terminator” on the Queue, it will get processed. So you do not prevent them from using “Terminator”. But if the client puts ThatQueueClass.TERMINATOR onto the Queue, it will get shut down.

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

Sidebar

Related Questions

Possible Duplicates: Java String.equals versus == whats the difference between ".equals and ==" public
Possible Duplicate: What is the purpose of the expression “new String(…)” in Java? It's
Possible Duplicates: String comparison and String interning in Java What is the difference between
Possible Duplicate: Java Strings: “String s = new String(”silly“);” I was going through some
Possible Duplicates: What's the difference between | and || in Java? Difference in &
Possible Duplicate: Java Generics To be more specific, whats the role of the <String>
Possible Duplicates: How can I Decode string? Java: How to decode HTML character entities
Possible Duplicate: Java: Parse a mathematical expression given as a string and return a
Possible Duplicates: How do I convert an InputStream to a String in Java? In
Possible Duplicate: Java - HashMap vs Map objects What's the difference between : Map

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.