Monday, July 30, 2012

C#-like TryParse Integer for Java

public static Integer TryParseInt(String someText) {
try {
return Integer.parseInt(someText);
} catch (NumberFormatException ex) {
return null;
}
}

1 comment:

how to get leech blood in ark said...

You should be careful about saying hashCode() returns a unique code in general. There should be very rare occurrences of it ever getting a repeated code for different values, but there are collisions none-the-less in some objects of greater than an int's size that have to accounted for.