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
0
votes
1 answer

Would writing millions of strings through a Writer be a memory and performance concern for the java string pool?

So say I have this code that streams back string back to a client with millions of rows of data. Would all the strings on each write be interned and thus give a hit on the java memory? If so, why in my case would it be or not be interned? I can't…
0
votes
2 answers

How Java Compiler treats the modified string at compile time

public class MyString { public static void main(java.lang.String[] args){ String a="Hello"; a=a.trim().concat("World"); String c="HelloWorld"; System.out.println(a==c);//returns false } interning should…
0
votes
1 answer

new string creates how many objects?

if I write a below code Scenario-1 [Initially no value in string constant pool] String s1 = new String("test"); then how many object created? As per my answer : two object created :: one is in string literal pool and other is in heap because of…
0
votes
1 answer

How String Pool Internal code as StringConstantPool is deprecated?

Could you Please let m me know the exact class which is behind Stringpool implementation as I wanted to know how it has implemented the FlyWeightDesign Pattern
0
votes
1 answer

Reference to which String object is returned from the pool when calling intern()

The Java Language Specification states that When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(java.lang.Object) method, then the string from the pool is …
0lt
  • 283
  • 2
  • 13
0
votes
2 answers

Java - What's wrong with choosing String to store password which is encrypted?

We store the password as char array in java and find the good reason for this. I came across an interview question stating "What if password is encrypted and we save that in String, is that okay? or why not?" What I could think is process of…
Ajeetkumar
  • 1,271
  • 7
  • 16
  • 34
0
votes
1 answer

How many String objects are created in Stringpool?

Consider the following example : String s1 "Hello"; String s2 = "World"; String s3 = s2 +s3; In the above example how many objects are created in Stringpool? Is string s3 added to Stringpool or it is separate object in Heap memory or does JVM…
0
votes
1 answer

How to create an object of string only on heap not in string pool?

I want to create an object of string on the heap and I have to make sure that the object is not created on string pool.
0
votes
0 answers

String in java behavior. How the String concatenation works during runtime?

For the below code: String bis = "good"; String cis ="good"; char[] ch = {'g','o','o','d'}; String temp=""; for (char c:ch){ temp=temp+c; } System.out.println(temp); System.out.println(cis==bis); //true System.out.println(bis==temp);…
0
votes
2 answers

Runtime constant pool - is filled up by variables created in runtime?

I'm not sure about some properties of runtime constant pool. Runtime constant pool, is filled up by the data from constant pool (from .class files, during class loading). But is it also filled up by variables created in runtime? Or are they…
0
votes
1 answer

Java : Number of String objects in string pool

My questions is regarding string pool in java. Case 1: StringBuilder sb = new StringBuilder(); sb.append("First"); sb.append("Two"); sb.append("Three"); sb.append("Four"); Case 2: StringBuilder sb = new…
0
votes
1 answer

If string pool is a part of Perm Gen Space, does it get garbage collected? And if it does, does it get collected during minor GC or full GC?

I have read that string pools are actually part of perm generation. And string pools do not generally get garbage collected, as a reference still exists even after GC runs and references are no longer used. So does it really get garbage collected?…
0
votes
1 answer

Is JVM string pool thread local? Will it cause any issue with this use case?

Many articles on internet specifies that using String.intern() in multi threading is bad but I really could not understand why it is bad.Using String.intern() always return a unique string from string pool,isn't it? If that is not the case then Is…
0
votes
1 answer

How to prevent a mybatis varchar from entering the string pool in java?

We have several sensitive fields in our database which need to be prevented from entering the Java string pool. All are VARCHAR in the database and we use StringBuilders in our code to prevent them from being put in the constant pool. We use…
LiamRyan
  • 1,892
  • 4
  • 32
  • 61
0
votes
2 answers

Java SE String pool

I can not understand why code below returns "false" String x="Hello World"; String z=" Hello World".trim(); System.out.println(x==z); //false I have read that "Strings are immutable and literals are pooled".After executing trim(), z will be…
Gunel
  • 23
  • 1
  • 8
1 2 3
8 9