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
  • 92,683
  • 18
  • 210
  • 320
Vivek Goel
  • 21,134
  • 28
  • 101
  • 178

1 Answers1

1

Using Google Guava Ints.tryParse

map(Ints::tryParse)
Tagir Valeev
  • 92,683
  • 18
  • 210
  • 320
Vivek Goel
  • 21,134
  • 28
  • 101
  • 178