Professional Documents
Culture Documents
JAVA
◦ Unboxing
⚫Unwrap(get the primitive value) from its relevant
object
Autoboxing and Unboxing
● Autoboxing
◦ Wrap a primitive data type into its object
type
◦ Unboxing
⚫Unwrap(get the primitive value) from its relevant
object
● listOfNumbers.add(3);
Back To Java History
● Now I want to add “3” into
listOfNumbers arraylist
● listOfNumbers.add(3);
◦ This gives me an ERROR!!!
Back To Java History
● Now I want to add “3” into
listOfNumbers arraylist
● listOfNumbers.add(3);
◦ This gives me an ERROR!!!
● listOfNumbers.add(3);
◦ This gives me an ERROR!!!
◦ listOfNumbers.add(new Integer(3));
Back To Java History
● IfI need to take that number “3” back,
then
Back To Java History
● IfI need to take that number “3” back,
then
● As method arguments
Lets Have Fun With Autoboxing
and Unboxing!
● As method arguments
◦ takeNumber method takes an Integer
object as input parameter. But we can use
int also!
Lets Have Fun With Autoboxing
and Unboxing!
● Return values
Lets Have Fun With Autoboxing
and Unboxing!
● Return values
◦ giveNumber method return int. but it can
be used int or Integer type!
Lets Have Fun With Autoboxing
and Unboxing!
● Boolean expressions
Lets Have Fun With Autoboxing
and Unboxing!
● Boolean expressions
Lets Have Fun With Autoboxing
and Unboxing!
● Operations on numbers
◦ Compiler do the trick!
Lets Have Fun With Autoboxing
and Unboxing!
● Assignments
Lets Have Fun With Autoboxing
and Unboxing!
● Assignments
End OF The Journey
● That’s
all about autoboxing and
unboxing!
End OF The Journey
● That’s
all about autoboxing and
unboxing!
● That’s
all about autoboxing and
unboxing!
● Thank you!