Performance ! which one is best
Hi guys could u explain which one is best in programming point of view
String s ="1 ";
double d = Double.parseDouble(s.trim());
String s ="1";
double d = Double.valueOf(s.trim()).doubleValue();
Can u explain the difference
Regards
Marimuthu.N
[409 byte] By [
muthu2007a] at [2007-11-27 10:46:18]

Both will execute in a fraction of a second. I doubt very much that worrying about which has a better performance is of any concern. If you write code, it works and doesn't take six hours to execute, then use it. When your code has an awful lag then you can start worrying about performance hits.
Thanks a lot
But one more question
Then why sun had provide these two methods?
Because i am asking interview point of view.
If suppose they asked the question like this then what i can tell
Could u please give suggestions
Regards
Marimuthu.N
Tell them: "premature optimization is the root of all evil".
http://en.wikipedia.org/wiki/Optimization_(computer_science)#When_to_optimize
jbisha at 2007-7-28 20:18:10 >

If you get asked this in an interview, first look closely at whoever asked the question. If they're smirking slightly, it's a trick question and you should say so, before quoting "premature optimization" at them. If not, and it looks like a genuine question, make your excuses and leave, then go to the pub
Without looking at the source code, I guess the first one will run slightly faster, since it just returns the primitive double value, where the second one first wraps it with its wrapper class and then unwraps it again.
But as the others said: this micro tuning which hardly is worth the effort!
-Puce
Pucea at 2007-7-28 20:18:10 >
