Friday, 23 August 2013

Java - About performance (memory or cpu)

Java - About performance (memory or cpu)

this question is about java coding, my question is easy so i'll explain it
with a little example :)
I have a String array full of arguments, and i have to check it's length
several times, so, it's better to save the amount of arguments (array
length) in a variable, or just call the length every single time?, i
suppose that storing a variable will consume more memory, and the other
way will use more cpu, just want to ask what do you think is better
thanks!
Example:
String[] arguments = {"a","b","c"};
int numberOfArguments = arguments.length;
if(numberOfArguments == 1)do whatever
if(numberOfArguments == 2)do whatever
if(numberOfArguments == 3)do whatever
etc
OR
String[] arguments = {"a","b","c"};
if(arguments.length == 1)do whatever
if(arguments.length == 2)do whatever
if(arguments.length == 3)do whatever
THANKS TO ALL!

No comments:

Post a Comment