Java wrapper class

Source: Internet
Author: User
Tags wrapper

Integer class

Construct method One: Integer (int number)

The method takes an int variable as a parameter to get an integer object.

Construction method Two: Integer (String str)

This method takes a string variable as a parameter to get an integer object

The following method returns the integer (int) value corresponding to the numeric character that invokes the method for the parseint () method.

public class Summation {public static void main (string[] args) {
String str[]={"1", "2", "3", "4"};
int sum=0;
for (int i=0;i<str.length;i++) {
int Myint=integer.parseint (str[i]);
Sum=sum+myint;
}
System.out.println ("The sum of each element in the array is" +sum);
}
The result of the execution is: the sum of each element in the array is the ToString () method in the ten integer class, which converts an integer object to a decimal string representation of tobinarystring (), tohexstring, and toocatlstring () The Charac method converts values into binary, hexadecimal, and octal string public class {
public static void Main (string[] args) {
String str_01=integer.tostring (456);
String str_02=integer.tobinarystring (456);
String str_03=integer.tohexstring (456);
String str_04=integer.tooctalstring (456);
System.out.println ("456 in decimal notation:" +str_01);
SYSTEM.OUT.PRINTLN (the binary representation of "456" is: "+str_02);
SYSTEM.OUT.PRINTLN (the hexadecimal representation of "456" is: "+str_03);
System.out.println (the octal representation of "456" is: "+str_04);
}
The result of the execution is: a decimal representation of 456 is: 456
The binary representation of 456 is: 111001000
The hexadecimal representation of 456 is: 1C8
The octal representation of 456 is: There are 4 710 integer constants: Max_value: Represents the maximum value that is desirable for an int type, and 2 of the 31-time square-1. Min_value: Represents the minimum value that is desirable for an int type, which is 2 of the 31-time Square. SIZE: The number of digits used to represent the value of int in the binary complement situation. Type: class instance of an int representing the base type output constant of the integer class Getcon {public static void main (string[] args) {
int maxint=integer.max_value;
int minint=integer.min_value;
int intsize=integer.size;
System.out.println ("The maximum value for int is:" +maxint);
System.out.println ("The minimum value for int is:" +minint);
System.out.println ("The most binary of int is:" +intsize);
}} Execution result: The maximum value of int is: 2147483647
The minimum value for int is:-2147483648
The binary of int is: The Booleanboolean type wraps the value of the base type Boolean in an object. An object of type Boolean contains only one field of type Boolean. This class also provides a number of methods for Boolean and string conversions, and provides some other constants and methods that are useful when working with Boolean. 1. Construct the method Boolean (Boolean value) code as follows: Boolean b=new Boolean (True); The method creates a Boolean object that represents the value parameter. The Boolean (String str) code is as follows: Boolean bool=new boolean ("str"), which creates a Boolean object with a String variable as a parameter. If the string parameter is not null and equals True when the case is ignored, a Boolean object that represents a true value is assigned, otherwise a value of false is created in the main method to create a Boolean object in a different construction method and calls Booleanvalue () method to re-create the object
Re-converted to Booleanpublic class Getboolean {public static void main (string[] args) {
Boolean B1=new Boolean (true);
Boolean B2=new boolean ("OK");
System.out.println ("B1:" +b1.booleanvalue ());
System.out.println ("B2:" +b2.booleanvalue ());
The result of the execution is: b1:true
B2:false byte type construction method The byte class provides an overloaded form of the following two constructor methods to create a byte class object. BYTE (byte) value creates a byte object in this way that represents the specified byte value. BYTE (string) str creates a Byte object in this way that represents the byte value constant represented by the string parameter: The Min_value:byte type is the desirable minimum value of the Max_value:byte type for the maximum size: The number of bits used in the binary complement form to represent a byte value. Type: class instance that represents the base type of byte public class Knowlege {
public static void Main (string[] args) {
BYTE b1,b2;
int b3;
b1=3;
b2=4;
B3=B1+B2;
SYSTEM.OUT.PRINTLN (B3);
}
The result of the execution is: 7 The Charactercharacter class wraps a base type in the object as a char value. An object of type character contains a single field of type Char. The class provides several methods to determine the character category (lowercase letters, numbers, and so on) and to convert characters from uppercase to lowercase, and vice versa. Constructor method: Character (char value) The constructor for the class must be of type char data. An object of type character created by this constructor contains the value provided by the type char type parameter. Once the character class is created, the value it contains cannot be changed. Character Mychar=new character (' s ') public class Uporlower {
public static void Main (string[] args) {
Character mychar1=new Character (' A ');
Character mychar2=new Character (' a ');
System.out.println (mychar1+ "Is it a capital letter?" +character.isuppercase (MYCHAR1));
System.out.println (mychar2+ "Is it a capital letter?" +character.islowercase (MYCHAR2));
}
The result of the execution is: A is capital letter? True
A is a capital letter? True constant is: connector_puncutattion: Returns a value of type Byte that represents the general category "Pc" of the Unicode specification species. UNASSIGNED: Returns a byte value that represents the general category "Cn" of the Unicode specification species. Titlecase_letter: Returns a byte value that represents the general category "Lt" in the Unicode specification. Double constructs a method double (double value): Creates a double class object based on a double argument. Double (string str): Constructs a newly assigned double object that represents a floating-point value of type Double, represented by a string. public class Casfe {
public static void Main (string[] args) {
Defining a double type variable
Double a=91.5;
Manual Boxing
Double B=new double (a);
Automatic Boxing
Double c=a;
SYSTEM.OUT.PRINTLN ("The result of boxing is" +b+ "and" +c ");
Defines a double wrapper class object with a value of 8
Double d=new double (87.5);
Manual unpacking
Double E = D.doublevalue ();
Double F = d;
System.out.println ("After unpacking the result is:" + E + "and" + f);
}
Execution Result: Boxed results are 91.5 and 91.5
The result of unpacking is: 87.5 and 87.5 constants: Max_exponent: Returns an int value representing the maximum exponent min_exponet a finite double variable may have: Returns an int value that indicates that a normalized double variable may have a minimum exponent. Negative_infinity: Returns a Double value that represents a constant that holds a negative infinity value of type Double. Positive_infinity: Returns a Double value that represents a constant that holds the value of a positive infinity of type double

Java 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.