Number Parsing : Convert from String « Data Type « Java Tutorial

Parsing is to do with the conversion of a string into a number or a date.

The purpose of number parsing is to convert a string into a numeric primitive type. Byte, Short, Integer, Long, Float, and Double classes, provide static methods to parse strings. For example, the Integer class has the parseInteger method with the following signature.

public static int parseInt (String s) throws NumberFormatException
  1. The Byte class provides the parseByte method,
  2. The Long class the parseLong method,
  3. The Short class the parseShort method,
  4. The Float class the parseFloat method, and
  5. The Double class the parseDouble method.

If the String does not contain a valid integer representation, a NumberFormatException will be thrown. For example, the following snippet uses parseInt to parse the string "123" to 123.

public class MainClass{

  public static void main(String[] args){
      int x = Integer.parseInt ("123");


2.36.Convert from String
2.36.1.Number Parsing
2.36.2.Integer.valueOf: Converting String to Integer
2.36.3.Integer.parseInt(): Converting String to int
2.36.5.sums a list of numbers entered by the user
2.36.6.Convert string of time to time object
2.36.7.Converting a String to a byte Number
2.36.8.Converting a String to a short Number
2.36.9.Converting a String to a int(integer) Number
2.36.10.Convert a String to Date
2.36.11.Convert String to character array
2.36.12.Convert base64 string to a byte array
2.36.13.Parse basic types