Logo

Programming-Idioms

  • Java
  • Python
  • Go
Integer i = Integer.valueOf(s, 10);

The second argument in the valueOf method denotes the radix (or base)
int i = new Integer(s).intValue();

Throws NumberFormatException if s does not contain a parsable integer
int i = s.chars()
     .map(x -> x - '0')
     .reduce((a, b) -> (a * 10) + b)
     .getAsInt();
int i = Integer.parseInt(s);

Throws NumberFormatException if s does not contain a parsable integer
i = int(s)
import "strconv"
i, err  := strconv.Atoi(s) 

Atoi(s) is shorthand for ParseInt(s, 10, 0). It yields type int.
import "strconv"
i, err := strconv.ParseInt(s, 10, 0)

Radix 10. The third argument 0 means "fit in implementation-specific int". But the result type is always int64.
Don't ignore the potential error err !
I : Integer := Integer'Value (s);

New implementation...