devxlogo

November 2, 2017

Parsing and Converting Numbers in Java

int x = Integer.valueOf(str).intValue(); int y = Long.valueOf(Double.valueOf(str).longValue).intValue(); To use the API without allocating unnecessary objects use the following lines of code: int x = Integer.parseInt(str); int y = (int) Double.parseDouble(str);