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
0 answers

How does String object get formed without use of Constructor?

String s = "abc"; This statement creates one String object. But how? Isn't object creation linked to Constructor? How is an object being created here without use of Constructor?
shanti
  • 270
  • 1
  • 4
  • 20
0
votes
1 answer

Does String Pool in Java behaves like LRU cache?

Strings are immutable and are managed in String pool. I wish to know as how this pool is managed. If there are large number of String literals being used in an application, ( I understand String builder should be used when modifications like append,…
nits.kk
  • 5,204
  • 4
  • 33
  • 55
0
votes
1 answer

c# string pool reference

If I have two strings with the same value, they should have the same reference, right? here is my case: string s1 = "aaa"; string s2 = "aaa"; Console.WriteLine(" s1: {0}; s2: {1}; equals: {2}", s1,s2, ReferenceEquals(s1, s2)); prints: s1: aaa; s2:…
Buda Gavril
  • 21,409
  • 40
  • 127
  • 196
0
votes
1 answer

String Pool management

Strings are immutable objects and are stored in the String Pool. Suppose in an application none of the strings are created using new operator. In this case also is it necessary to use equals method instead of == for String objects equality checks…
nits.kk
  • 5,204
  • 4
  • 33
  • 55
0
votes
1 answer

How does string pool works in java?

String s = new String("Java"); Will this statement creates two string objects. One which is stored in heap and another in string pool. I have searched a lot but couldn't find any documentation. If yes/no please give me reason/reference for the…
Babu Reddy H
  • 186
  • 1
  • 11
0
votes
3 answers

String s = new String("abc") memory allocation

String s = new String("abc") I know that this would create a new String object in Heap. But i am confused about a statement in SCJP book by Kathy Sierra. It states that the above statement would create an object in heap and at the same if the…
sujith
  • 665
  • 2
  • 9
  • 22
0
votes
0 answers

What is the difference between creating String as new() (inside heap not in string pool)and literal(inside string pool)?

When we create string with new() Operator, it’s created in heap and not added into string pool while String created using literal are created in String pool itself which exists in PermGen area of heap. is it right ???????? Is my explanation…
Vinay S Jain
  • 111
  • 1
  • 11
0
votes
2 answers

String memory allocation and string pool concepts

What is the difference between these two assignments, in terms of memory allocation and String pools. String b = "sunil" + "khokhar"; and String a = "sunil"; String b = a + "khokhar";
Sunil Khokhar
  • 370
  • 1
  • 5
0
votes
1 answer

Why does my variable contain "2122" and not "2322"?

This was a question on an exam. Luckily I picked the right answer, but I still can't see why it's right. Consider this program: class D { protected C c; public D(C c) { this.c = new C(c); } public C getC() { return c; } public…
flisk
  • 31
  • 2
0
votes
0 answers

Is there a way to access the String Pool indirectly?

I'm aware that the String Pool in Java is hidden (most likely for good purposes). However, what if you really wanna monitor and see what elements are in the pool? Can this be achieved using indirect methods (such as reflection or JNI), or is it…
Vince
  • 14,470
  • 7
  • 39
  • 84
0
votes
0 answers

How Java String Pool Working?

I am learning string implementations in java, got the following doubt while learning String s1 = "name1"; String s2 = "name1"; // both strings having same value; I know that, s1==s2 above comparison will return false (based on what i studied, ==…
lourdh
  • 449
  • 2
  • 12
  • 30
0
votes
3 answers

java String's immutability

If I run, String s1="abc"; then are there any differences between: String s2=new String(s1); and String s2="abc"; Here's what I'm confused about: The Head First Java says:"If there's already a String in the String pool with the same value, the…
-1
votes
3 answers

How many Strings are formed?

String a="hello"; String b=a+"Bye"; How many Strings are formed? From my understanding of Java. What happens in this code is: String a="hello"; // hello is created in string pool String b=a+"bye"; // new StringBuilder(a).append("bye") So totally…
-1
votes
1 answer

How to modify the size of String Pool in JVM?

I was reading a book on Java and there was an option mentioned to modify the size of the String Pool, and that option was XX:StringTableSize. When I tried this in my command line, I got an error saying this is an invalid flag, I tried both of the…
HusenPatel
  • 49
  • 5
-1
votes
2 answers

Does inbuilt String methods usage create new strings

As far as I know, Strings in Java are immutable and every time we try to change a String Java creates the new String in a String pool and re-references us to this new String. It is said that if we want to change a String we should use a String…
eldlit
  • 63
  • 7
1 2 3
8
9