There are mainly six sub-classes under Number class. These sub-classes define some useful methods which are used frequently while dealing with numbers.

                   

Associated Methods

             

                         

Methods Associated with Double

Method Name

Description

Example

1. toString() :

Returns the string corresponding to the double value.

double b = 55.05;

Double x = new Double(b); String s=Double.toString(x);

2. valueOf() :

returns the Double object initialised with the value provided.

String s=“45.55”;

Double d=Double.valueOf(s);

3. parseDouble() :

returns double value by parsing the string. Differs from valueOf() as it returns a primitive double value and valueOf() return Double object.

String s=“45.55”;

Double d=Double.parseDouble(s);

4. equals() :

Used to compare the equality of two Double objects. This methods returns true if both the objects contains same double value.

If(double1.equals(double2))

//true

else     // false

5. compareTo()

Used to compare two Double objects for numerical

equality. Returns a value less than 0,0,value greater than 0 for less than,equal to and greater than.

If(double1.compareTo(double2))

//true

else     // false

6. compare() :

Used to compare two primitive double values for numerical equality.

If(compare(double1,double2)==0)

//equal

7. byteValue() :

returns a byte value corresponding to this Double Object.

byte b=double1.byteValue();

8. shortValue() :

returns a short value corresponding to this Double Object.

short s=double1.shortValue();

9. intValue() :

returns a int value

corresponding to this Double Object

int i=double1.shortValue();

10. longValue() :

returns a long value corresponding to this Double Object.

long l=double1.longValue();

11. doubleValue() :

returns a double value corresponding to this Double Object.

double d=double1.doubleValue();

12. floatValue() :

returns a float value corresponding to this Double Object.

float f=double1.floatValue();

Methods Associated with Float

Method Name

Description

Example

1. toString() :

Returns the string corresponding to the float value.

float b = 55.05;

Float x = new Float (b); String s= Float.toString(x);

2. valueOf() :

returns the Float object initialised with the value provided.

String s=“45.55”;

Float d= Float.valueOf(s);

3. parseFloat() :

returns float value by parsing the string. Differs from valueOf() as it returns a primitive float value and valueOf() return Float object.

String s=“45.55”; Float d= Float.parseDouble(s);

4. equals() :

Used to compare the equality of two Float objects. This methods returns true if both the objects contains same float value.

If(float1.equals(float2))

//true

else     // false

5. compareTo()

Used to compare two Float objects for numerical equality. Returns a value less than 0,0,value greater than 0 for less than,equal to and greater than.

If(float1.compareTo(float2))

//true

else     // false

6. compare() :

Used to compare two

primitive float values for

numerical equality.

If(compare(float1,float2)==0)

//equal

7. byteValue() :

returns a byte value corresponding to this Float Object.

byte b=float1.byteValue();

8. shortValue() :

returns a short value corresponding to this Float Object.

short s= float1.shortValue();

9. intValue() :

returns a int value corresponding to this Float Object.

int i= float1.shortValue();

10. longValue() :

returns a long value corresponding to this Float Object.

long l= float1.longValue();

11. doubleValue() :

returns a double value corresponding to this Float Object.

float d= float1.doubleValue();

12. floatValue() :

returns a float value corresponding to this Float Object.

float f= float1.floatValue();

 

Methods Associated with Integer

1. toString()

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()

6. parseInt()

7. getInteger() : returns the Integer object representing the value associated with the given system property or null if it does not exist.

8. byteValue()

9. intValue()

10. doubleValue()

11. shortValue()

12. longValue()

13. floatValue()

14. equals()

15. compareTo()

16. compare()

 

Methods Associated with Character

1. boolean isLetter(char ch) : This method is used to determine whether the specified char value(ch) is a letter or not. The method will return true if it is letter([A-Z],[a-z]), otherwise return false.

                             

2. boolean isDigit(char ch) : This method is used to determine whether the specified char value(ch) is a digit or not.

                     

3. boolean isWhitespace(char ch) : It determines whether the specified char value(ch) is white space. A whitespace includes space, tab, or new line.

                               

4. boolean isUpperCase(char ch) : It determines whether the specified char value(ch) is uppercase or not.

5. boolean isLowerCase(char ch) : It determines whether the specified char value(ch) is lowercase or not.

6. char toUpperCase(char ch) : It returns the uppercase of the specified char value(ch).

7. char toLowerCase(char ch) : It returns the lowercase of the specified char value(ch).

               

8. toString(char ch) : It returns a String class object representing the specified character value(ch) i.e a one-character string.

                 

Methods Associated with Boolean

  1. parseBoolean(String s) : This method parses the string argument as a boolean. The boolean returned represents the value true if the string argument is not null and is equal, ignoring case, to the string “true”, otherwise return false.

                boolean b1 = Boolean.parseBoolean("True");

                 System.out.println(b1); //Output: true

  1. booleanValue() : This method returns the value of this Boolean object as a boolean primitive.

                boolean b1 = Boolean.booleanValue("True");

                System.out.println(b1); //Output: true

  1. valueOf(boolean b) : This method returns a Boolean instance representing the specified boolean If the specified boolean value is true, it returns Boolean.TRUE or if it is false, then this method returns Boolean.FALSE.

                    boolean b1 = true;

                    Boolean b3 = Boolean.valueOf(b1);

                    System.out.println(b3);                       //Output: true

  1. valueOf(String s) : This method returns a Boolean with a value represented by the specified string ‘s’. The Boolean returned represents a true value if the string argument is not null and is equal, ignoring case, to the string “true”.
  2. toString(boolean b) : This method returns a String object representing the specified If the specified boolean is true, then the string “true” will be returned, otherwise the string “false” will be returned.
  3. toString() : This method returns a String object representing this Boolean’s value. If this object represents the value true, a string equal to “true” is returned. Otherwise, the string “false” is returned.
  4. equals(Object obj) : This method returns true iff the argument is not null and is a Boolean object that represents the same boolean value as this object.
  5. compareTo(Boolean b) : This method “compares” this Boolean instance with passed argument ‘b’.
  6. compare(boolean x, boolean y) : This method is used to “compares” primitives boolean variables.

 

Methods Associated with Other Wrapper Classes

//Same as Double,Float and Integer……..