
Overview of Processing of Some Languages 335
11.1.6 Type Conversion
As mentioned above Java is a strongly typed language and if you need to change the type of variables
Java generally requires an explicit conversion. The following examples illustrate such conversions.
Conversion to String
The following examples show conversion from other types to Strings:
// Convert from int to String
String s1 = String.valueOf(10); // "10"
// Convert from double to String
String.valueOf(Math.PI); // "3.141592653589793"
// Convert from Boolean to String
String s3 = String.valueOf(1 < 2); // "true"
// Convert from date to String
String s4 = String.valueOf(new Date()); ...