Java AdvancedLesson 75Free preview
Java Wrapper Classes
This lesson is part of Java · All levels
Summary
Wrapper classes wrap primitive types into objects, for example int into integers and double into double. This is necessary when primitive types should be treated as objects, for example in a generic collection. In addition, the Number class became the parent of Integer, Double, Float, Long, Short, and Byte.
Key points
- Primitive pairs: int→Integer, char→Character, boolean→Boolean; the rest is equal to the initial capital letters
- Autoboxing wraps the primitive automatically, unboxing reopens it automatically
- It's more economical because it keeps caches of -128 to 127
- Static methods are useful: Integer.parseInt(), Integer.MAX_VALUE, Character.isDigit()
- Wrapper constructors have been deprecated since Java 9, use valueOf()
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.