More than just a song and dance.

advertisement
More than just a song and dance.
 They are objects that store primitive variable values:
 Integer – stores an int
 Double – stores a double
 Character – stores a char
 Boolean – stores a boolean
 Sometimes you want a primitive value stored as an
object. This allows you to:
 Store primitives in complex data structures such as
ArrayLists
 They are pass by reference instead of pass by copy
 They provide some additional helper methods
 parseInt(String s) – takes in a String and converts it
into the corresponding Integer
 toHexString(int i) – converts an integer to a
hexadecimal String
 toBinaryString(int i) – converts an integer to a binary
String
//Declaring variables
Integer x = 5;
Double y = 6.7;
Character z = 'z';
Boolean flag = false;
//Using parseInt
String numInText = "29274";
Integer a = Integer.parseInt(numInText);
//Performing operation
Integer b = x + a;
System.out.println(b);
ArrayList <Integer> numbers = new ArrayList<Integer>();
numbers.add(3);
numbers.add(5);
numbers.add(7);
System.out.println(numbers);
Download