I have the java guava library, and was wondering if they have a tryparse type helper method that will attempt to parse a string to a integer, and return a boolean if it failed.
In c#, I can do:
if(int.tryparse("somestring", out myInt)) {
}
Was hoping java has something similiar (don’t want to re-invent the wheel if it exists).
Guava has Ints.tryParse(String) as of 11.0. It doesn’t work quite like the C# method (no out parameters) though. It returns an
Integerthat’snullif the string couldn’t be parsed, so for your example you’d use it like this: