Java Reference
In-Depth Information
To String
From String
Type
boolean
String.valueOf(boolean) Boolean.parseBoolean(String)
byte
String.valueOf(int)
Byte.parseByte(String, int base)
char
String.valueOf(char)
str .charAt(0)
short
String.valueOf(int)
Short.parseShort(String, int base)
int
String.valueOf(int)
Integer.parseInt(String, int base)
long
String.valueOf(long)
Long.parseLong(String, int base)
float
String.valueOf(float) Float.parseFloat(String)
double
String.valueOf(double) Double.parseDouble(String)
To convert a primitive type to a String you invoke one of the static
valueOf methods of String , which for numeric types produces a base 10
representation.
The Integer and Long wrapper classesas described in Chapter 8 also
provide methods toBinaryString , toOctalString , and toHexString for other
representations.
To convert, or more accurately to parse a string into a primitive type
you invoke the static parse Type method of the primitives type's corres-
 
Search WWH ::




Custom Search