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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:08:49+00:00 2026-05-23T04:08:49+00:00

we make the following String objects? String str1 = new String(ABC); String str2 =

  • 0

we make the following String objects?

String str1 = new String("ABC");
String str2 = new String("ABC");
String str3 = "ABC";
String str4 = "ABC";

Two questions on above :

  1. system.out.println("valof str1 "+str1 ); — it prints str1 as ABC
    But when we compare if(str1==str2), it compares the refrences of string object. How does
    jvm get to differnce?

  2. str1 has differnt reference from str2 and str3 but str3 and str4 have same references so does jvm check if the string we are going to create with equal operator(instead of new) already exists (if it exist it does not create new object just assign the same refernce to new variable i.e str4) but it does not do this verfication in case of new operator?

  • 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-23T04:08:49+00:00Added an answer on May 23, 2026 at 4:08 am

    In Java, string literals (bare "ABC" instead of new String("ABC")) are interned. That is, there is only one copy stored in the JVM, and that is always the copy that’s used. That’s why they compare equal when using ==.

    The following comparisons are also always true:

    str1.intern() == str2.intern()
    str1.intern() == str3
    str2.intern() == str3
    str1.intern() == str4
    str2.intern() == str4
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can someone help me figure out the following make file? BINS=file1 file2 file3 all:
I use functions like the following to make temporary tables out of crosstabs queries.
I want to make the following types of objects. This is my higher-level desire
In Django, you can make database queries like the following: Model.objects.filter(name__icontains = 'bob') The
hello i am trying to make a map containing objects as the following :
I make the following call to the DB. @patientRegistration = PatientRegistration.find(:all, :conditions=>[name = '#{patientName}'])
How do I make the following url forbidden in apache; main/index.php?site=ing I have tried
How do you make the following code work? example = %%(test)% % {'test':'name',} print
i'm trying to make the following routes .. and currently i'm going about this
Can someone tell me how I can make the following output? I have a

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.