To conquer without peril, one ends up triumphing without glory
help me correct this code
What can I do when my i+1 variable is greater than the size of the array?
To conquer without peril, one ends up triumphing without glory
To conquer without peril, one ends up triumphing without glory
Tiam Bezalel wrote:strings with the same hashCode
To conquer without peril, one ends up triumphing without glory
strings with the same hashCode
the two methods (yours and mine) give the same results,
To conquer without peril, one ends up triumphing without glory
determine the number of strings that are definitely created in the string pool
Norm Radder wrote:
determine the number of strings that are definitely created in the string pool
Given the hashCodes of 1,2,1,2,2 what is the desired results?
2 unique hashCodes
max count of 3 with same hashCodes
To conquer without peril, one ends up triumphing without glory
yes !!!
Norm Radder wrote:
yes !!!
Ok, which of the two choices is the one?
Or do you want both?
To conquer without peril, one ends up triumphing without glory
Carey Brown wrote:Output of histogram:
Note that the hash code is determined by the characters and sequence that they appear in the String. It has nothing to do with any "pool".
Whenever a string literal is created, the compiler checks the String Constant Pool first. If it encounters the same string, then instead of creating a new string, it returns the same instance of the existing string to the variable.
To conquer without peril, one ends up triumphing without glory
Tiam Bezalel wrote:I'm currently trying to better understand the creation of strings in the string pool of heap memory. Using the little program I've created, I'd like to determine the number of objects (strings of characters) that are created definitively in the string pool of heap memory.
All you have demonstrated so far is that some strings which are identical have the same hash code. This is simply a rule of how hash codes behave and it has nothing to do with the system's string pools.
String pool is a storage space in the Java heap memory where string literals are stored. It is also known as String Constant Pool or String Intern Pool. It is privately maintained by the Java String class. By default, the String pool is empty. A pool of strings decreases the number of String objects created in the JVM, thereby reducing memory load and improving performance.
To conquer without peril, one ends up triumphing without glory
To conquer without peril, one ends up triumphing without glory
To conquer without peril, one ends up triumphing without glory
Tiam Bezalel wrote:thanks .I need your advice on determining the total number of strings created in the stringPool. Is hashing the right approach?
Why? You have an automatic heap; trying to determine its contents sounds like keeping a dog and barking yourself.Tiam Bezalel wrote:hi,
I'd like to determine the number of strings created in the Heap(StringPool). . . .
Are you familiar with String#intern()? I don't think it creates a new object. Nor does it cause literals to be put into the String pool. You will find both those points explained in the link above.. . .
3-Using String.intern() method
. . .
When we use the String.intern() method, JVM puts the string literal in the String Pool (if not already present) . . .
Campbell Ritchie wrote:
Tiam Bezalel wrote:hi,
I'd like to determine the number of strings created in the Heap(StringPool). . . .
Why? You have an automatic heap; trying to determine its contents sounds like keeping a dog and barking yourself.
Campbell Ritchie wrote:Are you familiar with String#intern()? I don't think it creates a new object.
The API wrote:When the intern method is invoked, if the pool already contains a string equal to this String object as determined by the equals(Object) method, then the string from the pool is returned. Otherwise, this String object is added to the pool and a reference to this String object is returned.
Exactly!Paul Clapham wrote:. . . intern must simply add a reference to the pool. . . .
You can't create String literals at runtime; they are in the source code and are loaded into memory, in this case the String pool, when the class concerned is loaded.Tiam Bezalel wrote:When we create new string literals using the new keyword, memory is allocated to those String objects in the Java heap memory outside the String Pool.
It's fun to be me, and still legal in 9 states! Wanna see my tiny ad?
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
|