String pool memory | SoloLearn: Learn to code for FREE!

+28

String pool memory

I am only aware of two kinds of memory stack and heap.Is string pool memory some different kind of memory?If not then why is it given a separate name?

7/6/2018 4:40:38 AM

World Champion

16 Answers

New Answer

+7

String pool is a memory area within the heap memory area only i.e. it is not any other kind of memory area... String object when created using double quotes, jvm first check for the string in pool and if the string already exits, then same reference is given to the object and if no string is found in pool then new string is added to the pool and reference of this is given. In other case, when we create a string object with new operator, then in this case JVM creates a new string object in the Heap itself instead of searching for the string in the pool.

+17

Thanks Tarika for your answer

+14

Thanks a lot Jain Rishav Amit for your elaborate explanation👍

+14

Yeeaah, String subject. To really understand it, use some IDE and a debugger, put a breakpoint and compare different scenarios. It is worth more than any lesson read. EDIT: please use Mission Control too

+14

It is a java performance tool, highly recommend it for You to test and play with it. A lot of tutorials are telling how things work, but I believe it is better to "see" memory address and think for a while why and how it is done internally

+5

Thanks for the info Jakub Dubański Sounds interesting.. I will be looking forward to use it..

+5

also you can use method hashCode( ) to see how two String refer to each other if there content are same . i.e

+4

thankq Jain rishav amit

+3

Jakub Dubański I am not aware about Mission control... whats that?

+1

as far as i know objects are store in a heap and variables are in stack, 1/3 rd of heap memory is reserved for string literal pool.

0

im want lern writ📝 Ap java but littel langoech english and no univer sit student im hom mayker and iron im help

0

👌👌👉

0

thanks for ur answer

0

0

-3

Hello Where are you from???