What is the difference between size of a String and length of a String in java? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

What is the difference between size of a String and length of a String in java?

They both sounds same, but what is the difference?

23rd Nov 2017, 7:24 AM
Jayanth Sai Kiran
Jayanth Sai Kiran - avatar
1 Answer
+ 4
in evry aspect.... generally : suppose a string is "asdgh" it have a specific space...for allocation.. if each char comsumps k memory its 5*k in total but length is...number of chars..= 5 so...total memory consumption= length * char space same as in array a array of 5 element has length 5 space taken= byte of each elemnt * 5 (assuming all are same element type)
23rd Nov 2017, 7:28 AM
sayan chandra
sayan chandra - avatar