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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T20:25:23+00:00 2026-05-30T20:25:23+00:00

Firstly apologies if this a very basic question, I’m just curious to know the

  • 0

Firstly apologies if this a very basic question, I’m just curious to know the difference between the following string definitions

String x= "hello";
String y = new String("hello");

I knew that in java String is a Class its neither a primitive nor a Wrapper(Correct me if this a misconception). Consider a class A, I’ve seen the following declarations for any class so far. i think A c; is valid and A a = new A(); is also valid. I’m confused with A a ="xyz"; this is how we declared a String as in above first type of definition. I’m sure that the above two definitions are absolutely different, like if i say x==y it returns false. I understand that y is the reference to the String object. What is x there, how is it stored in memory, interestingly i found that both x and y can access all the methods of String class.

Then what is the advantage of one over other.Can i know the applicability of each.

  • 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-30T20:25:24+00:00Added an answer on May 30, 2026 at 8:25 pm

    From the 2nd edition of Joshua Bloch’s “Effective Java”:

    String s = new String("stringette");// DON'T DO THIS!
    

    The statement creates a new String instance each time it is executed,
    and none of those object creations is necessary. The argument to the
    String constructor (“stringette”) is itself a String instance,
    functionally identical to all of the objects created by the
    constructor. If this usage occurs in a loop or in a frequently invoked
    method, millions of String instances can be created needlessly. The
    improved version is simply the following:

    String s = "stringette";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Firstly regrets if this is a very basic question and i promote that I'm
firstly, I very much apologize for my poorly written title of this question. So
Firstly apologies for the length of this question, and for asking about the Facebook
Firstly I know that there are many question and solutions to correct thread marshalling
Firstly, I do not have any malicious intent out of this question. I would
Frstly my apologies if this is a duplicate question. I have tried to find
Firstly, sorry about the question title, it may not be very descriptive for my
Firstly apologies for the title, I don't know if it describes what I am
Firstly I realise that this is a familiar question, it seems to pop up
Firstly, this is a homework assignment, and I am very new to programming in

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.