Type Wrappers - 12,17 Flashcards
What are type wrappers?
Primitive types like int, double sometimes need object representation to get more functionality.
Can wrap the type in a class/object to get more. e.g.
Double, Integer, Character.
what is boxing and unboxing?
process of encapsulating a value within an object and visa versa. From primitive types to wrapper objects.
Integer iob = Integer.valueOf(100)
make a double thats the numeric value of string “3214”
Double d1 = Double.valueOf(“3214”)
Covert string to number.
String str;
int i;
str = “120”
i = Integer.parseInt(str)
explain method in Integer:
static int parseInt (String s)
Converts the string s and returns its integer value
explain method in Integer
int intValue()
returns the value of an Integer object as an int type
Explain constructor methods in Integer:
Integer (int n)
Integer (String s)
constructs and Integer object form an int type or String type
Integer methods list
pic