Wrapper Classes

Java Wrapper Classes :

In object oriented programming, a wrapper class is a class that encapsulates types, so that those types can be used to create object instances and methods in another class that need those types. So a primitive wrapper class is a wrapper class that encapsulates, hides or wraps data types from the eight primitive data types.

  • Provides a way of wrapping primitive values in an object so that a primitive can be treated as an object.
  • Provides a set of utility methods for primitives.
  • Wrapper classes are available in java.lang package.
Situation when we required Wrapper Classes:
  • When primitives are required to be added to a collection object.
  • When we want to return a primitive from a method that returns an object.
  • When converting primitives to and from String objects.
  • When converting primitives & String objects to and from different bases like binary, octal & hexadecimal.
Wrapper Classes: prowessapps.in
Object Creation:
Integer i1 = new Integer(5);
Integer i2 = new Integer("5");

Float f1 = new Float(5.6f);
Float f2 = new Float("5.6f");

Double d1 = new Double(6.7);
Double d2 = new Double("6.7");

Character c = new Character('a');

Boolean b1 = new Boolean(true);
Boolean b2 = new Boolean("true");
Boolean b3 = new Boolean("TrUe");

returns a signed numeric value equivalent to string s

returns wrapper object equivalent to primitive

returns wrapper object equivalent to String

returns wrapper object equivalent to String as per give base(DEC-10,BIN-2,OCT-8,HEX-16) value. 

returns a new String object representing the integer i

returns the value of this type as a byte

returns the value of this type as a double

returns the value of this type as a float

returns the value of this type as an int

returns the value of this type as a short

returns the value of this type as a long
class Test
 public static void main(String[] a) 
  String s = "A";
  Integer i1 = Integer.valueOf(s,16);
  byte b = i1.byteValue();

Next topic is generics


Training For College Campus

We offers college campus training for all streams like CS, IT, ECE, Mechanical, Civil etc. on different technologies like
C, C++, Data Structure, Core Java, Advance Java, Struts Framework, Hibernate, Python, Android, Big-Data, Ebedded & Robotics etc.

Please mail your requirement at info@prowessapps.in

Projects For Students

Students can contact us for their projects on different technologies Core Java, Advance Java, Android etc.

Students can mail requirement at info@prowessapps.in


(8AM to 10PM):

+91-8527238801 , +91-9451396824

© 2017, prowessapps.in, All rights reserved