Questions tagged [string-pool]

A string pool allows a runtime to save memory by preserving immutable strings in a pool, so that instances of common strings can be reused throughout the application instead of creating multiple instances of them.

In computer science, string interning is a method of storing only one copy of each distinct string value, which must be immutable. Interning strings makes some string processing tasks more time- or space-efficient at the cost of requiring more time when the string is created or interned. The distinct values are stored in a string intern pool.

Possible duplicate of .

133 questions
2
votes
4 answers

Difference between concatenation at run time and compile time in java

public class First { public static void main(String[] args) { String str1="Hello ",str2="World",str3="Hello World"; System.out.println(str3==("Hello "+"World")); //Prints true System.out.println(str3==("Hello…
Frosted Cupcake
  • 1,909
  • 2
  • 20
  • 42
2
votes
2 answers

Comparing command line arguments reference return false while array of String return true

Currently i am working with String manipulation and while doing demo i have found some different behaviour. Below is my code. public class HelloWorld{ public static void main(String []args){ String str1 = "Hello"; String str2 = "Hello"; …
Pratik
  • 944
  • 4
  • 20
2
votes
4 answers

Java String object creation

I have been reading Java String object and I had this question - String x="a"; String y="b"; Does it create two objects in Java?
user3717604
  • 21
  • 1
  • 2
2
votes
2 answers

Strings in Java

I'm curious to know the exact reasons for the behavior of String objects in the following case. I'm eager to learn about the following snippet and how it works. Snippet String s1 = "I belong to String pool"; String s2 = new String("I'm present on…
Saurabh Gokhale
  • 53,625
  • 36
  • 139
  • 164
2
votes
1 answer

Method Local Strings Memory Allocation?

I understand how String pool and intern() method works in java. Here is a brief introduction. String.intern() in Java 6 In those good old days all interned strings were stored in the PermGen – the fixed size part of heap mainly used for storing…
Dangling Piyush
  • 3,658
  • 8
  • 37
  • 52
1
vote
3 answers

Java String intern function and ==

Recently I'm learning Hotspot JVM. When learning the string constant pool and String intern function, I encountered a very weird situation. After browsing a lot of answers, I still can’t explain this phenomenon, so I’m sending it out to discuss with…
DracoYu
  • 37
  • 3
1
vote
1 answer

Problems re-appending spaces to a string in python

I have a problem where I'm trying to take the text string string "The quick brown fox jumps over the extraordinarily lazy dog" and convert it into an array of characters whilst also storing an array of integers where the integer represents the end…
1
vote
2 answers

Java String Pool with String constructor and the intern function

I learned about the Java String Pool recently, and there's a few things that I don't quiet understand. When using the assignment operator, a new String will be created in the String Pool if it doesn't exist there already. String a = "foo"; //…
1
vote
3 answers

Does string pool store literals or objects?

Stackoverflow is full of questions related to different types of String initialization. I understand how different is String s = "word" to String s = new String("word"). So no need to 'touch' that topic. I noticed that different people refer that…
Stefan
  • 969
  • 6
  • 9
1
vote
1 answer

Is string pool works in case of returning values from method?

I have some knowledge about string pool in Java. All examples in the network conected with creating variables explicitly. But what will happen if I return hardcoded string from method. Is it use string pool or string will be created again and again…
Yurii Kozachok
  • 615
  • 1
  • 7
  • 21
1
vote
2 answers

does intern() method have implication on performance?

I have some confusion about the usefulness of the intern() method. This line of code can clear my confusion: String a = new String("abc").intern(); How many objects will the above line of code create? If it will create an object in heap memory as…
parichay07
  • 45
  • 5
1
vote
1 answer

Where a String saves when the object creation has a concatenation?

As we know the following String is saved in the String Constant Pool. String a = "AB"; The String objects created as below will be saved in Heap. String b = new String("AB"); String e = b.concat("C"); At this time, Can anyone explain where the…
Chamalee De Silva
  • 687
  • 1
  • 9
  • 28
1
vote
0 answers

Remove string pool

I want to generate a large string (20MB+) every 3 seconds. Now my problem is that my string pool get larger and larger and i have no RAM for that. Anyone knows how to remove the string pool manually? Thanks.
Idan Str
  • 614
  • 1
  • 11
  • 33
1
vote
0 answers

What data structure does String Pool in java uses internally?

I understand the use cases of String Pool in java, but I am wondering what data structure is used while implementing String Pool. I mean when we talk about interning of strings, JVM needs to search the entire String Pool for any existing String. So…
pritamprasad
  • 159
  • 1
  • 13
1
vote
2 answers

Difference between Strings added directly and with references

I came across a question asking the output of the below: String s1 = "String 1"; String s2 = "String 2"; String s3 = s1 + s2; String s4 = "String 1" + "String 2"; System.out.println(s3==s4); Output - false Now, since the…
Vikas
  • 107
  • 1
  • 10
1 2 3
8 9