Wrapper classes for basic data type objects

Source: Internet
Author: User

First, the concept

The advantage of encapsulating a basic data type as an object is that more functional methods can be defined in the object to manipulate the data.

Second, common Operation 1. Common operation:

Used for conversions between the base data type and the string.

Basic data types

Packing class

Byte

Byte

Short

Short

Int

Integer

Long

Long

Float

Float

Double

Double

Char

Character

Boolean

Boolean

2.Object object parent of all objects

Object to basic data type conversions need to be directly converted through wrapper class string and base data type must also be done through wrapper class

Iii. Common Application Scenario 3.1 numeric values of the base type are converted to strings (string type)

There are two ways: a). Basic data type + "", B). String.valueof (basic data type)

int A  = ten= a + "" = string.valueof (a);
3.2String types of strings converted to basic data types

Wrapper classes that use basic data types

String STR3 = "n"; int i = integer.parseint (STR3); double d = double.parsedouble (STR3);
Conversions between 3.3 and binary

A) decimal conversion to other binary

// decimal conversion into binary System.out.println (integer.tobinarystring (30)); // 11110, // decimal into octal System.out.println (integer.tohexstring (30)); // 1e // convert decimal to hexadecimal System.out.println (integer.tooctalstring (30)); //  $

b) other conversions into decimal

System.out.println (Integer.parseint ("11110", 2)); //  -
3.4 Conversion of basic data types and wrapper classes

A). basic data type converted to wrapper class

New Integerin2= integer.valueof (30);

b). The wrapper class is converted into a basic data type

// jdk1.7 cannot be converted directly between int a = in.intvalue (); // jdk1.7 can then be converted by itself . int b  = in;

Wrapper classes for basic data type objects

Related Article

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.