Tuesday, 15 May 2012

Java autoboxing ValueOf(String) -



Java autoboxing ValueOf(String) -

what think next line of code?:

string s= "10.0"; float f = float.valueof(s).floatvalue();//1

is necessary? why improve using such syntax rather using:

float f = float.valueof(s);//2

it still gives same results taking advantage of autoboxing function.

in short question is: why should 1 take first syntax instead of sec one? same?

in short question is: why should 1 take first syntax instead of sec one? same?

well, utilize neither of them, because both of them generate intermediate float object, not needed. , wherever needed, work boxing.

for now, should rather utilize float.parsefloat(string) method, generates primitive float.

as far similarity concerned, no not same. 2nd 1 involves auto-unboxing float float, while there no unboxing in first case. conversion using given method.

java string int boxing value-of

No comments:

Post a Comment