Basic data wrapper classes and simple conversions for Java Basics (11)

Source: Internet
Author: User
Tags wrapper

First, Basic Data Type wrapper class

    1. The reference data type is typically capitalized on the base data type, except for int, char, where the reference data type of the int class Integer,char is character
    2. Relationship:

Relationships between basic data types are compatible with each other

There is no relationship between the wrapper class for the base data type

3. Conversion between the basic data type and the basic data type wrapper class

3.1 Boxing: Encapsulates a basic data type into a corresponding wrapper class type

Grammar:

jdk>1.5 Automatic packing

A reference to the wrapper type Object = Basic data type;

static Integer valueOf (int i) is called by default

jdk<1.5 Manual Boxing

Reference to wrapper type Object = new wrapper type (base data type)

3.2 Unpacking: Splitting the wrapper type into a basic data type

Grammar:

jdk>=1.5 Automatic Unpacking

Basic data type variable name = object of wrapper class;

the int intvalue () method is called by default to complete

jdk<1.5 Manual Unboxing

Basic data type variable name = a reference to the wrapper class's object. Intvalue ();

Second, conversion issues between strings and base data types

    1. Convert String to int

First: Integer (String s) using integer construction method

Integer in = new Integer (s); Required to be a number in a string

int c = In.intvalue (); Unpacking

Second type: static int parseint (string s) complete string to int using static method in integer class

int d = integer.parseint (s);

2.int Conversion to String

The first type: String s=e+ "";

Second type: integer in= new Integer (e);

String s2 = in2.tostring (); Convert integer to String type

The third type: String s3 = Integer.tostring (e);

Fourth type: String class static string valueOf (int i)

Precautions:

    1. Although the basic data type wrapper class is a reference data type, it passes the value itself when the method passes the parameter.
    2. = = The address value is always compared when comparing objects in Java A==integer b-->false

Basic data wrapper classes and simple conversions for Java Basics (11)

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.