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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:24:29+00:00 2026-06-17T02:24:29+00:00

Possible Duplicate: Questions about Java’s String pool I have a doubt in java Strings

  • 0

Possible Duplicate:
Questions about Java’s String pool

I have a doubt in java Strings object creation.

String s1 = "Hello"+"world";
String s2 = s1+"Java";

in this program how many String objects will be created and how ?please explain it.
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-06-17T02:24:30+00:00Added an answer on June 17, 2026 at 2:24 am

    The answer is 3

    Two String objects will be created once per JVM start:

    • “Helloworld”
    • “Java”

    Both will be interned, because they are constants (known at compile time).

    They will be reused every time this code runs. A StringBuilder will be created to concatenate the two String above. References to them will be assigned to s1 and s2.

    Here’s the bytecode for the code:

       0:   ldc #37; //String Helloworld
       2:   astore_1
       3:   new #39; //class java/lang/StringBuilder
       6:   dup
       7:   aload_1
       8:   invokestatic    #41; //Method java/lang/String.valueOf:(Ljava/lang/Object;)Ljava/lang/String;
       11:  invokespecial   #47; //Method java/lang/StringBuilder."<init>":(Ljava/lang/String;)V
       14:  ldc #50; //String Java
       16:  invokevirtual   #52; //Method java/lang/StringBuilder.append:(Ljava/lang/String;)Ljava/lang/StringBuilder;
       19:  invokevirtual   #56; //Method java/lang/StringBuilder.toString:()Ljava/lang/String;
       22:  astore_2
       23:  return
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Questions about Java's String pool Recently I read a java article and
Possible Duplicate: Questions about Java's String pool String s1 = length; String s2 =
Possible Duplicate: Questions about Java’s String pool What's the difference between the two ways
Possible Duplicate: Questions about Java's String pool Guys what is the difference between these
Possible Duplicate: Java: “implements Runnable” vs. “extends Thread” I have two questions about multithreaded
Possible Duplicate: How do I compare strings in Java? Java String.equals versus == I
Possible Duplicate: Is Java pass by reference? Hi guys, I have a question about
Possible Duplicate: Java final modifier This is just a small question about preferences. What
Possible Duplicate: newbie questions about malloc and sizeof I am trying to read strings
Possible Duplicate: Java question about autoboxing and object equality / identity Integer i1 =

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.