Program apes are very lazy, you know!
What we are sharing today is the integer wrapper class. In real-world development, we often need to operate an integer, or a variety of conversions and so on. I will give you a specific explanation of the use of the integer today. Look at the code:
Package Com.herman.test;public class Integertest {public static void main (string[] args) {System.out.println (" Constant in integer **************************** "); SYSTEM.OUT.PRINTLN ("Maximum value of Integer: \ t" +integer.max_value); SYSTEM.OUT.PRINTLN ("Minimum value of Integer: \ t" +integer.min_value); SYSTEM.OUT.PRINTLN (maximum number of digits for integer: (the number of digits in binary complement for an int value.) ) \ t "+integer.size); System.out.println ("type of Integer: \ t" +integer.type); System.out.println (); System.out.println ("Use ************************** of Methods in Integer"); int i=1000; SYSTEM.OUT.PRINTLN ("Binary representation of 1000: \ t" +integer.tobinarystring (i)); SYSTEM.OUT.PRINTLN (the total number of "1" in the binary string of "1000": \ T "+integer.bitcount (i));/** * Numberofleadingzeros calculation method is: (integer.size)- Integer.tobinarystring (+) Length () */system.out.println (the total number of consecutive "0" from the leftmost of "1000" in binary string: \ t "+ Integer.numberofleadingzeros (i)); SYSTEM.OUT.PRINTLN (the total number of consecutive "0" from the rightmost in the binary string of "1000": \ T "+integer.numberoftrailingzeros (i));/** * Integer decode (String NM) * Given a 10 binary, 8 binary, 16 binary regardless of what kind of binary string, * This method can convert the incoming string into an integer of 10 digits and return. */system.out.println ("8 octal is 010, converted to 10 binary: \ T "+integer.decode (" 010 ")); System.out.println ("10 decimal is 10, converted to 10: \ T" +integer.decode ("10")); SYSTEM.OUT.PRINTLN ("16 Hex is 0X10, converted to 10: \ T" +integer.decode ("0X10")); System.out.println ("1000 reverses the bit order of the integer twos complement: \ t" +integer.reverse (i)); System.out.println ("1000 Reverses the Order of integer bytes: \ t" +integer.reversebytes (i));/** * Gets the integer sign, returns 1 as negative, returns 1, 0 returns 0 */system.out.println ("1000 Gets the integer symbol: \ t" +integer.signum (i)); System.out.println ("Create an Integer object of 1000: \ t" +integer.valueof (i)); SYSTEM.OUT.PRINTLN ("The use of the Integer.valueof object (1000 of the radix number): \ t" +integer.valueof ("+");/** * Integer.getinteger The function of (String) is to get the integer value of the system property according to the specified name. * The first parameter will be considered to be the name of the system attribute. * System properties can be obtained via System.getproperty (java.lang.String) method. * attribute value string is interpreted as an integer and returned as an integer object representing the value. * The specific description of the possible number format can be found in the GetProperty definition description. */system.out.println ("Getinteger is System configuration: \ T" +integer.getinteger ("Sun.arch.data.model")); System.out.println ("Getinteger is System configuration: \ T" +integer.getinteger ("java.version")); System.out.println ("Getinteger is System configuration: \ T" +integer.getinteger ("java.lang.String")); /** * Assumes that there is an integer value for the Sun.arch.data.model system attribute, returns the integer number * Assuming that the integer value is not present, then returns the value of the reference (VAL) 2 */SYSTEM.OUT.PRINTLN ("Getinteger fetch Is the system configuration: \ T "+integer.getinteger (" Sun.arch.data.model ", 16)); Returns an int value with a single 1 bit, the position of the highest 1 bit in the specified value, otherwise assuming that the specified itself equals 0, returns 0 System.out.println ("returns the highest bit is 1, the other bit is 0 (right): \ t" + Integer.highestonebit (i)); System.out.println ("Returns the highest bit is 1, the other bit is 0 (left): \ t" +integer.lowestonebit (i)); System.out.println ("Move I to the left distance, assuming the distance is negative, then move right-distance:\t" +integer.rotateleft (I, 2)); System.out.println ("Move I unsigned right distance, assuming distance is negative, move left-distance. Negative affirmation will be shifted to positive: \ t "+integer.rotateright (I, 2)); System.out.println (); System.out.println ("Method of the integer object uses ******************************"); integer obj=new integer (1000); System.out.println ("1000 is converted to a number of byte types: \ t" +obj.bytevalue ()); System.out.println ("Integer1000 and Integer2000 size comparison: \ t" +obj.compareto (New Integer (2000))); System.out.println ("Integer2000 and Integer1000 size comparison: \ t" +new Integer. CompareTo (obj)); System.out.println ("Integer1000 converted to double type: \ t" +obj.doublevalue ()); System.out.println ("Integer1000 and Integer2000 size comparison: \ t" +obj.equals (New Integer (2000))); System.out.println ("Integer2000 and Integer1000 size comparison: \ t" +new Integer. Equals (obj)); System.out.println ("Integer2000 and Integer1000 size comparison: \ t" +new integer. Equals (New Integer (2000))); System.out.println ("Integer1000 hash code: \ T" +obj.hashcode ()); SYSTEM.OUT.PRINTLN (int value of "Integer1000: \ T" +obj.intvalue ()); SYSTEM.OUT.PRINTLN ("Long value of Integer1000: \ T" +obj.longvalue ()); SYSTEM.OUT.PRINTLN ("Short value of Integer1000: \ T" +obj.shortvalue ()); System.out.println ("parse string 1000 to int type: \ t" +integer.parseint ("1000")); /** * Integer.parseint ("1000", 2) * Returns the 2 binary (string) of the first parameter (parameter 2 is the binary of the conversion) */System.out.println ("1000 binary returned 2" +integer . parseint ("1000", 2)); /** * Binary Conversion */SYSTEM.OUT.PRINTLN ("10,000 binary to Binary" +integer.tobinarystring (i)); SYSTEM.OUT.PRINTLN ("10,000 binary to octal: \ t" +integer.tooctalstring (i)); SYSTEM.OUT.PRINTLN ("10,000 binary to 16 binary: \ t" +integer.tohexstring (i)); System.out.println ("Hexadecimal turns into decimal: \ t" +integer.valUeof ("FFFF", +). toString ()); System.out.println ("Hexadecimal turns into binary: \ t" +integer.tobinarystring (integer.valueof ("FFFF", 16))); SYSTEM.OUT.PRINTLN ("hexadecimal into octal: \ t" +integer.tooctalstring (integer.valueof ("FFFF", 16)); System.out.println ("Octal turns into decimal: \ T" +integer.valueof ("576", 8). toString ()); System.out.println ("Octal turns into binary: \ t" +integer.tobinarystring (integer.valueof ("23", 8)); System.out.println ("octal turns into 16 binary: \ t" +integer.tohexstring (integer.valueof ("23", 8)); SYSTEM.OUT.PRINTLN ("Binary goto decimal: \ t" +integer.valueof ("0101", 2). toString ()); System.out.println ("binary octal: \ t" +integer.tooctalstring (Integer.parseint ("0101", 2)); SYSTEM.OUT.PRINTLN ("Binary turn 16 binary: \ t" +integer.tohexstring (Integer.parseint ("0101", 2)); System.out.println (); System.out.println ("1000 binary form leftmost highest one and all 0 after high, and finally returns the result of int" +integer.highestonebit (i));}}
Performance effects such as the following:
Click Resources to download:http://download.csdn.net/detail/xmt1139057136/7309395
Welcome everyone to pay attention to my personal blog, or add QQ group 135430763 to learn from each other.
Detailed explanation of the integer wrapper class in Java (Java binary operation, all-in conversion)