GeekInterview.com
Series: Subject: Topic:
Question: 33 of 1118

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
Asked by: Interview Candidate | Asked on: Sep 12th, 2011
Showing Answers 1 - 1 of 1 Answers
sumathi

Answered On : 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.

Yes  1 User has rated as useful.
  
Login to rate this answer.

Give your answer:

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

Related Open Questions

Ads

Connect

twitter fb Linkedin GPlus RSS

Ads

Interview Question

 Ask Interview Question?

 

Latest Questions

Interview & Career Tips

Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.