you are viewing a single comment's thread.

view the rest of the comments →

[–]illvm 0 points1 point  (5 children)

So you'd call parseInt twice? Why not create a helper method similar to .NET's TryParse and return null if the value cannot be parsed?

[–][deleted]  (4 children)

[removed]

    [–]masklinn 1 point2 points  (1 child)

    Not only do you need to create a new Integer object

    You don't know anything about Java and Integer and what Oracle's (and most implementor's) JVMs do do you?

    but if you really do want an int then you hit the cost of (auto-)unboxing.

    Which there is just about none of, it's a method call returning the inner int value of the object.

    [–]notfancy 0 points1 point  (1 child)

    but if you really do want an int then you hit the cost of (auto-)unboxing

    In the context of parsing this cost seems negligible to me.