Term 2 - Lesson 12: Wrapper Classes
Wrapper Classes
* "Wraps" a primitive in a class type * One for each of the primitive types Ex. Double ----> double Integer ----> int
"Integer" Class
* Wrapper class for int * Implements "Comparable", so there must be a compareTo method
Which of the following isn't a wrapper class? A) Double B) Integer C) String
C) String
Which of the following isn't a method of the "Integer" wrapper class? A) toString B) equals C) Integer D) MAX_VALUE E) valueOf
D) MAX_VALUE
Example of using the "Double" class
Double n1 = new Double(98.232); ArrayList <Double> h = new ArrayList <Double> (); h.add(n1);
What is the maximum value an Integer can hold?
Integer.MAX_VALUE;
Is the output of the following a positive or negative value? Integer n1 = new Integer(45); Integer n2 = new Integer(56); System.out.println(n1.compareTo(n2));
Negative
"Double" Class
Wrapper class for double
How would you properly add the value 75 to the following ArrayList? ArrayList<Integer> temps = new ArrayList<Integer>();
temps.add(new Integer(75));