Wrapper Classes(Part-1) in Java

There a eight primitive data types in java. These primitive types are dedicated to the classes which are called wrapper classes.

As the name shows wrapper classes wraps the primitive data type. It uses primitive data types to represent as an object of that class.
For example: for int , there is Integer wrapper class, for float, there is Float wrapper class.
Wrapper classes stores the same values as primitive types store but the difference is that these are classes and have instances in primitive types forms. These classes are used to make objects of the form of encapsulated primitive data types and to use inherited methods.
Wrapper classes are imported from java.lang package.

Methods and Constructors

1. Integer class methods

parseInt(String s): This method returns the integer value which would be equivalent to the String s argument.
For example: parseInt(“10”) will return us integer value 10.

toString(int i): This method will return an object of string that will represent integer i in the argument. In simple, this method converts the argument into string object.

byteValue(): this method coverts integer value into bytes and returns values as bytes.

doubleValue(): this method coverts integer value into double(Data type) and returns values as double.

floatValue(): This method coverts integer value into float and returns values as float. intValue(): This method convert integer value into type int and return values as int. longValue(): This method convert integer value into type long and return values as long.

intCompareTo(int i): This method compares the value of Integer object with the value to int i argument and will return numerical values. If values are same then it will return ‘0’, if Integer object value is less than ‘i’ then return some negative value otherwise returns positive value.

static intcompare(int i, int j: This method compares the value of i and j argument and will return numerical values. If values are same then it will return ‘0’, if value of i is less than j then return some negative value otherwise returns positive value.

boolean equals(Object i): This method compares the values of Integer object and object i and returns true if they are equal otherwise returns false.

Constructors

Integer(int i)
This method will make an integer object and initialize it with value i.

Integer(String s)
This method will make an integer object and initialize it with int with equivalent String s.

2. Boolean Class Methods

Boolean booleanValue(): This method returns Boolean value for Boolean object as boolean primitive.

Int CompareTo(Boolean b): This method will return true if Boolean object and argument b have same value, return negative value id Boolean object is false and b is true, otherwise return positive value.

Boolean equals(Object o): This method will compare the value of Boolean object with object o in argument and return true if they have same value.

Static Boolean parseBoolean(String s): This method will return true if the argument string s has true otherwise false.

Static Boolean ValueOf(Boolean b): This method will return a object of type boolean, which is equivalent to b.

Static Boolean ValueOf(String s): This method will return true if the argument string contains true otherwise false.

Constructors:

Boolean(Boolean b): This method will make a Boolean object and assign it with b.

Boolean(String s): This method will make a Boolean object and assign it with value true if String s is not null and contains “true”.

3. Character Class Methods

Static Boolean IsDigit(char c): This method will return true if char c is a digit character else false.

Static Boolean IsLetter(char c): This method will return true if char c is a letter character else false.

Static Boolean IsLetterOrDigit(char c): This method will return true if char c is either a digit character or letter character else false.

Static Boolean IsLoweCase(char c): This method will return true if char c is in lowercase otherwise will return false.

Static Boolean IsUpperCase(char c): This method will return true if char c is in Uppercase otherwise will return false.

Static Boolean IsWhiteSpace(char c): This method will return true if char c is a whitespace character otherwise will return false.

Static char ToLowerCase(char c): This method will return lowercase of char c.

Static char ToUpperCase(char c): This method will return Uppercase of char c.

Constructors:

Character(char c): This method will make a Charatcer object and assign it with char c argument.

Leave a Reply