Java Object-oriented learning (3)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.