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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T20:28:16+00:00 2026-06-04T20:28:16+00:00

String s = java; s.substring(1); // ava Considering the immutability of strings, compiler doesnot

  • 0
String s = "java";
s.substring(1); // ava

Considering the immutability of strings, compiler doesnot modify 's' but creates a new object or you can say that there is space for 'java' as well as 'ava' in memory..

What happens to this 'ava', as nothing is pointing to it or it’s not being referenced by anything..

One more question… If i would have written String s = new String("java"); // ‘java’ is not in string literal pool….

The ‘ava’ would be in the string literal pool then or not ?

  • 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-04T20:28:18+00:00Added an answer on June 4, 2026 at 8:28 pm

    What happens to this ‘ava’, as nothing is pointing to it or it’s not being referenced by anything..

    The newly constructed String object immediately becomes eligible for garbage collection.

    As to your second question, I don’t think there’s any difference between the following two expressions as far as the string literal pool is concerned:

    String s = "java";
    String s = new String("java");
    

    In both cases, the literal "java" would be in the pool. (But in the second case, s would not refer to the "java" string that’s in the pool, but to a different String that also has the characters "java".)

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

Sidebar

Related Questions

I recently discovered that the java.lang.String.substring method does not return a new string, but
prehistory: Java regular expression for binary string I can extract a substring with binary
How to print the reverse of the String java is object orientated language without
I've a Java String with new lines(\n), say for example String value = This
I have a simple java String object and wanna serialize/deserialize it, using XStream. Serialization
Can someone suggest me some JAVA string library for JAVA ME that includes basic
I have the following code: String table; private DB.ConnectMAS mas=new DB.ConnectMAS(); java.sql.ResultSet rs1 =
Possible Duplicate: How to see if a substring exists inside another string in Java
I am getting the following error: java.lang.StringIndexOutOfBoundsException: length=13243; regionStart=32; regionLength=-39 at java.lang.String.startEndAndLength(String.java:593) at java.lang.String.substring(String.java:1474)
java.lang.String JavaDoc says nothing about the default indexOf(String) substring search algorithm. So my question

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.