Wrapper class
- The class wraps primitive type. - When handle 8 types of primitive type as object. =>why? OOP is Object-Oriented Programming. It needs to be as Object. 90% is Object and remains are primitive type because of performance.
primitive type | wrapper class | constructor | example |
boolean | Boolean | Boolean(boolean value) Boolean(String s) | Boolean b = new Boolean(true); Boolean b2 = new Boolean("true"); |
char | Character | Character(char value) | Character c = new Character('a'); |
byte | Byte | Byte(byte value) Byte(String s) | Byte b = new Byte(10); Byte b2 = newByte("10"); |
short | Short | Short(short value) Short(String s) | Short s = new Short(10); Short s2 = new Short("10"); |
int | Integer | Integer(int value) Integer(String s) | Integer i = new Integer(100); Integer i2 = new Integer("100"); |
long | Long | Long(long value) Long(String s) | Long l = new Long(100); Long l2 = new Long("100"); |
float | Float | Float(double value) Float(float value) Float(String s) | Float f = new Float(1.0); Float f = new Float(1.0f); Float f = new Float("1.0f"); |
double | Double | Double(double value) Double(String s) | Double d = new Double(1.0); Double d = new Double("1.0"); |
Last updated