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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T06:27:10+00:00 2026-06-06T06:27:10+00:00

Any String literal in Java is a constant object of type String and gets

  • 0

Any String literal in Java is a constant object of type String and gets stored in the String literal pool.

Will String literals passed as arguments to the methods also get stored in the String literal pool?

For example when we write,

System.out.println("Hello");

OR

anyobj.show("Hello");

will a String “Hello” be created and stored in the String literal pool?

Is there any way to print the contents of the String literal pool?

  • 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-06T06:27:11+00:00Added an answer on June 6, 2026 at 6:27 am

    Every time you use a String literal in your code (no matter where) the compiler will place that string in the symbol table and reference it every time it encounters the same string somewhere in the same file. Later this string will be placed in the constant pool. If you pass that string to another method, it still uses the same reference. String are immutable so it is safe to reuse them.

    Take this program as an example:

    public class Test {
    
        public void foo() {
            bar("Bar");
        }
    
        public void bar(String s) {
            System.out.println(s.equals("Bar"));
        }
    
    }
    

    After decompiling with javap -c -verbose you’ll find out the following:

    const #2 = String   #19;    //  Bar
    //...
    const #19 = Asciz   Bar;
    
    
    public void foo();
        //...
        1:  ldc #2; //String Bar
    
    
    public void bar(java.lang.String);
        //...
        4:  ldc #2; //String Bar
    

    There are two entries in constant pool: one for String (#2) referencing the actual characters (#19).

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

Sidebar

Related Questions

I'm getting this warning Format not a string literal and no format arguments? Any
This is regarding the Java String Constant Pool. In one of my Programs i
In Java you can try to convert any String value to Integer, but when
hi i want to convert a string literal in to string value, can any
I've read that multiline string literals were proposed to be added in Java 7.
Is using a String() constructor as against string literal beneficial in any scenario? Using
Possible Duplicate: SnowLeopard Xcode warning: “format not a string literal and no format arguments”
The Java language documentation says: If a primitive type or a string is defined
I have following queries regarding java string pool: Is it a part of java
Is there any single-line string literal syntax in Ruby that allows string interpolation but

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.