Java Basic Type wrapper class

Source: Internet
Author: User
Tags binary to decimal decimal to binary

Java Basic type wrapper class:

Basic data type Basic type wrapper class

BYTE byte
Short Short
int Integer
Long Long
float float
Double Double
Char Character
Boolean Boolean

Here is a representative explanation of the integers and charater classes.

Integer class

The Integer class wraps the value of a primitive type int in the object. The class provides several methods for converting between int and String types, as well as some constants and methods that are useful when working with int types.

Member variables:

(1) The maximum value that the public static final int max_value:int type can represent
(2) The minimum value that the public static final int min_value:int type can represent

Construction Method:

(1) public Integer (int value).
(2) Public Integer (string s) Note: This string must be made up of numeric characters.
Note: JDK5 new, automatic unboxing
Code:
Integer i1 = new Integer (100);
Integer i2 = new Integer ("100");
Integer i3 = 100;i3++;//Auto-unboxing

Member Methods:

(1) public int intvalue (): Returns the value of the Integer as the int type.
(2) public static int parseint (string s): Converts a string argument to an integer
(3) public static string toString (int i): Converting an integer argument to a string
(4) public static integer valueOf (int i): Returns an integer instance representing the specified int value
(5) public static integer valueOf (string s): Returns an integer object that holds the value of the specified String

The functions of the integer class:

One, the int type and the string type mutual conversion

INT--String
(1) String s = "" +number
(2) string.valueof (number)
(3) intager.tostring (number)
Note: Recommended Way (2)
String--INT
Integer.parseint (str)
Note: Str must be made up of numeric characters.

Second, the common basic conversion

(1) public static String tobinarystring (int i): decimal to Binary
(2) public static String tooctalstring (int i): decimal to octal
(3) public static String tohexstring (int i): decimal to hexadecimal
Decimal to another binary
public static String toString (int i,int radix): Radix binary range: 2-36, because 0,... 9,a...z
Other binary to Decimal
public static int parseint (String s,int Radix)

Three, automatic packing attention to problems

(1) This code:
Integer x = null;
x+=10;
Note: The code will appear nullpointerexception
Recommendation: First determine if NULL, then use the object
(2) Integer data is directly assigned, and if the data value is between 128 and 127, the data will be fetched directly from the buffer pool.
The code indicates:
Integer i1 = 127;
Integer i2 = 127;
System.out.println (I1 = = I2);
System.out.println (I1.equals (I2));

Integer i3 = 128;
Integer i4 = 128;
System.out.println (i3 = = I4);
System.out.println (I3.equals (I4));

Character class

The character class wraps the value of a base type char in an object. The class provides several methods to determine the categories of characters (lowercase letters, numbers, and so on), and to convert characters from uppercase to lowercase, from small to uppercase.

Construction Method:
Character (char value)

Member Methods:
(1) public static Boolean isuppercase (char ch): Determines whether the given character is uppercase characters
(2) public static Boolean islowercase (char ch): Determines whether the given character is lowercase characters
(3) public static Boolean isdigit (char ch): Determines whether a given character is a numeric character
(4) public static char touppercase (char ch): Converts the given character to uppercase characters
(5) public static char toLowerCase (char ch): Converts the given character to lowercase characters

Java Basic Type wrapper class

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.