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