I. JAVA7 enhanced PACKAGING class
To solve the problem that the basic data types in Java 8 cannot be used as object type variables, Java provides wrapper classes that define the corresponding reference types for the basic data types in 8.
java1.5 after the JDK provides automatic boxing and automatic unpacking functions, so the basic type and packaging type can be directly loaded. Wrapper classes can implement conversions of basic types and string types:
1. Use the wrapper class's parsexxx (String s) static method.
2. Is the constructor provided by the wrapper class
The valueof method provided by the string class enables the implementation of the basic type to be converted to a string.
The sample code is as follows:
Package Test1;public class Primitivate2string {public static void main (string[] args) {String intstr= "123";// Turn a specific string into int variable int it1 = Integer.parseint (INTSTR);//int it2 = new Integer (INTSTR); System.out.println (IT1); String ftstr= "4.56";//a specific string is converted to float variable float ft1 = float.parsefloat (FTSTR);//float ft2 = new float (FTSTR); System.out.println (FT1);//turn a float variable into a string variable string ftStr2 = String.valueof (2.342); System.out.println (FTSTR2);//Convert a double variable to string type string dbstring = String.valueof (3.453563); System.out.println (dbstring);//Convert a Boolean variable to stringstring blstr = String.valueof (true); System.out.println (BLSTR);//But in fact, if there is a more convenient way to convert a base type to a string type: //The base type variable and "" are calculated. String INTSTR1 = 5 + ""; System.out.println (INTSTR1);}}
Java Object-oriented learning (3)