0

I am converting a Optional<String> to Integer by .map(Integer::parseInt). Is there a way to avoid NumberFormatException if string can't be parsed as int?

I want to avoid try/catch statement for this.

Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186

1 Answers1

1

Using Google Guava Ints.tryParse

map(Ints::tryParse)
Tagir Valeev
  • 97,161
  • 19
  • 222
  • 334
Vivek Goel
  • 22,942
  • 29
  • 114
  • 186