+ 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
2 Answers
+ 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