wrapper class
A class, such as Integer for int, that wraps a primitive value in an object so it can be stored in collections or be null.
In more detail
Every primitive has one: Integer, Long, Double, Boolean, Character and so on. Because a wrapper is a reference type it can be null, and unboxing a null wrapper throws NullPointerException. Keep primitives in numeric code and use wrappers where an object is required.
Example
Integer boxed = 42;Related terms
- boxing — The automatic conversion between a primitive, such as int, and its wrapper object, such as Integer, which the compiler inserts for you.
- primitive type — A basic built-in type, such as a whole number or true-or-false, whose values are held directly rather than as objects.
- null — A special value meaning no value or no object, set on purpose to show that something is empty or absent.
- NullPointerException — The unchecked exception thrown when code uses a null reference as if it pointed to an object.
Taught in
- Primitive And Reference Types — Modern Java: Virtual Threads & High-Throughput Services
- Generics And Collections — Modern Java: Virtual Threads & High-Throughput Services
- Fifty Items, Five Traps — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- A Hundred And Twenty Minutes, Fifty Items — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Promotion, Wrappers And The Math API — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Values And Flow — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Overloading And Varargs — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Scope, var And Immutable Objects — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Inheritance, Overriding And Object's Methods — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sealed Types, Casts And Pattern Matching — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Object-Oriented Java — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Checked, Unchecked, Catch And Finally — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Arrays: Declare, Sort, Search, Compare — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Generics, Bounds And Wildcards — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lists, Sets, Maps, Deques And Sequenced Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Exceptions, Arrays And Collections — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Lambdas, Functional Interfaces And Method References — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Reduction, Grouping And Partitioning — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Sprint: Lambdas And Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Thread Safety: Locks And Atomics — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Concurrent Collections And Parallel Streams — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep
- Final Review And Exam Day — Oracle Certified Professional: Java SE 21 Developer (1Z0-830) Exam Prep