📘 Lesson  ·  Lesson 34

Wrapper Classes & Autoboxing

Wrapper Classes & Autoboxing

What are Wrapper Classes?

Wrapper classes turn primitives into objects (int→Integer, double→Double). Needed for collections, which only store objects.

Autoboxing and Unboxing

Integer obj = 5;       // autoboxing: int -> Integer
int x = obj;           // unboxing: Integer -> int

ArrayList<Integer> list = new ArrayList<>();
list.add(10);          // int auto-boxed into Integer

Primitive to Wrapper

PrimitiveWrapper
intInteger
doubleDouble
charCharacter
booleanBoolean

Summary

  • Wrapper classes make primitives into objects (int→Integer).
  • Autoboxing converts automatically; needed for collections.

Wrapper Classes क्या हैं?

Wrapper classes primitives को objects बनाती हैं (int→Integer, double→Double)। Collections के लिए ज़रूरी, जो सिर्फ objects रखती हैं।

Autoboxing और Unboxing

Integer obj = 5;       // autoboxing: int -> Integer
int x = obj;           // unboxing: Integer -> int

ArrayList<Integer> list = new ArrayList<>();
list.add(10);          // int auto-boxed into Integer

Primitive से Wrapper

PrimitiveWrapper
intInteger
doubleDouble
charCharacter
booleanBoolean

सारांश

  • Wrapper classes primitives को objects बनाती हैं (int→Integer)।
  • Autoboxing अपने आप convert करता है; collections के लिए ज़रूरी।
← Back to Java Tutorial
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

\n