I am using int duration = Integer.parseInt(durationInString) to convert String object to primitive integer value. I am using this in a while loop and the integer conversion happens every second until the end of video duration. For example – if Video is 2 min I will call Integer.parseInt 120 times.
I wanted to know if every call to Integer.parseInt creates a object? If so is it a bad idea to have it called continuously?
Any help is very much appreciated.
Note: I am working on Android application
Thanks,
SKU
Internally the method might create objects, but since the return value is an
intit is not producing any objects that leak out to you, the caller. I would not worry about the efficiency concerns of object creation like this, since most JVMs have garbage collectors that are specifically optimized to collect young objects that are no longer referenced. If you have reason to believe that this method is creating objects at a rate that actually causes a problem, then pull out a profiler to inspect it. I would wager that it is not a bottleneck.Hope this helps!