How to find size of string in java

How to know that a string require how much bytes in memory......
Ex. String s="abc";
String s=new String("abc");
How much memory is used for s and s2

Showing Answers 1 - 3 of 3 Answers

sumathi

  • Oct 6th, 2011
 

You can check
Runtime r = Runtime.getRuntime() ;
r.freeMemory() ;
before and after the creation of the new Object you can check the memory and by subtraction u can get the used memory. Not accurate but useful.

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions