Sunday, July 9, 2023

WRAPPER CLASS-INTEGER

 Constructors: 

1.public Integer(int b)

2.public Integer(String s) throws NumberFormatException


Methods: 

1. toString() : Returns the string corresponding to the int value. 

2.toHexString() : Returns the string corresponding to the int value in hexadecimal form, that is it returns a string representing the int value in hex characters-[0-9][a-f] 

3.toOctalString() : Returns the string corresponding to the int value in octal form, that is it returns a string representing the int value in octal characters-[0-7] 

4. toBinaryString() : Returns the string corresponding to the int value in binary digits, that is it returns a string representing the int value in hex characters-[0/1] 

5.valueOf() : returns the Integer object initialised with the value provided. 

6.valueOf(String val,int radix): Another overloaded function which provides function similar to new Integer(Integer.parseInteger(val,radix))

7.parseInt() : returns int value by parsing the string in radix provided. Differs from valueOf() as it returns a primitive int value and valueOf() return Integer object. 

8.rotateLeft() : Returns a primitive int by rotating the bits left by given distance in two’s complement form of the value given. When rotating left, the most significant bit is moved to the right-hand side, or least significant position i.e. cyclic movement of bits takes place. Negative distance signifies right rotation.

9.rotateRight() : Returns a primitive int by rotating the bits right by given distance in the twos complement form of the value given. When rotating right, the least significant bit is moved to the left hand side, or most significant position i.e. cyclic movement of bits takes place. Negative distance signifies left rotation. 

10.bitcount() : Returns number of set bits in twos complement of the integer given. 

11. numberOfTrailingZeroes() : Returns number of 0 bits following the last 1 bit in twos complement form of the value, i.e. if the number in twos complement form is 0000 1010 0000 0000, then this function would return 9. 

12.equals() : Used to compare the equality of two Integer objects. This method returns true if both the objects contain the same int value. Should be used only if checking for equality. In all other cases, the compareTo method should be preferred. 

13.compareTo() : Used to compare two Integer objects for numerical equality. This should be used when comparing two Integer values for numerical equality as it would differentiate between less and greater values. Returns a value less than 0,0, a value greater than 0 for less than, equal to and greater than. 

14.static int max(int a, int b): This method returns the greater of two int values as if by calling Math.max.

15.static int min(int a, int b): This method returns the smaller of two int values as if by calling Math.min.

16.static int sum(int a, int b): This method adds two integers together as per the + operator.

17.

No comments:

Post a Comment