Java Fundamentals Hardening 66: How to construct the integer of the basic type wrapper class

Source: Internet
Author: User

1. Overview of the Integer class

(1) The integer class wraps a value of a primitive type int in the object, and an object of type integer contains a field of type int.

(2) This class provides several methods for converting between int and string types, as well as some other constants and methods that are useful when dealing with int types.

2. How integer is constructed

(1) public Integer (int value);

(2) Public Integer (String s);

3. Case of the Integer class

1  Packagecn.itcast_02;2 3 /*4 * Method of constructing integer:5 * Public Integer (int value)6 * Public Integer (String s)7 * Note: This string must be made up of numeric characters 8  */9  Public classIntegerdemo {Ten      Public Static voidMain (string[] args) { One         //Mode 1 A         inti = 100; -Integer II =NewInteger (i); -System.out.println ("II:" +II); //ii:100, not an address value (integer overrides the ToString () method)  -         //Mode 2 -String s = "100"; -         //NumberFormatException +         //String s = "abc"; -Integer III =NewInteger (s); +System.out.println ("III:" +III); A     } at}

The operating effect is:

Java Fundamentals Hardening 66: How to construct the integer of the basic type wrapper class

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.