Java Reference
In-Depth Information
U0400.pdf . And the URL http://www.unicode.org/charts/ is a good
place to start whenever you need to find the code point corresponding to a given charac-
ter.
1-5. Converting to and from a String
Problem
You have a value in a primitive data type, and you want to represent that value as a
human-readable string. Or, you want to go in the other direction by converting a
human-readable string into a primitive data type.
Solution
Follow one of the patterns from Listing 1-5 . The listing shows conversion from a string
to a double-precision floating-point value, and shows two methods for getting back to a
string again.
Listing 1-5 . General Pattern for String Conversions
package org.java8recipes.chapter01.recipe1_05;
public class StringConversion {
public static void main (String[] args) {
double pi;
String strval;
pi = Double.parseDouble("3.14");
System.out.println(strval = String.valueOf(pi));
System.out.println(Double.toString(pi));
}
}
 
 
Search WWH ::




Custom Search