Lesson 21- Class Wrappers + Variable conversion


Topics Discussed: Class Wrappers and changing types using toString / parseint / parseDouble

Source code http://ideone.com/hXBHcF



Class wrappers:

Class wrappers exist to help us manipulate primitives of similar type. Some code that you’ll want to be aware of is:


Double d = null; // Class wrappers can accept null values
Double.parseInt(d); //Class wrappers can be used to change the variable type as long as the data is the same
**NOTE** When changing variable type, there can be a loss of precision.   Example
double d= 4.779;
int i = Double.parseInt(d); // I would now be equal to 4.   Everything after the decimal would be dropped.