0Pricing
Java Academy · Lesson

Parsing and Valueof

Convert strings to numbers.

Text Into Numbers

User input and files arrive as String text. To do math you must convert those strings into numbers.

Wrapper classes provide two families of methods for this: parseXxx returns a primitive, and valueOf returns a wrapper object.

parseInt Returns a Primitive

Integer.parseInt takes a string and returns a plain int. This is the most common parsing method.

public class Main {
    public static void main(String[] args) {
        int n = Integer.parseInt("123");
        System.out.println(n + 1);
    }
}

All lessons in this course

  1. Primitive vs Wrapper Types
  2. Autoboxing and Unboxing
  3. Parsing and Valueof
  4. Autoboxing Pitfalls
← Back to Java Academy