CoderSathi
  • Tutorial
    • Java Tutorial
    • Swing Tutorial
    • JDBC Tutorial
    • Java String Tutorial
    • Servlet and JSP Tutorial
  • Mongo DB
  • AWS
  • DevOps
  • Linux
  • Git
Home > Java > Wrapper Classes in Java

Java Tutorial

  • Introduction
    • What is Java
    • History Of Java
    • Install Java
    • What is JVM
    • JDK vs JRE vs JVM
    • Java Bytecode
    • OOP vs POP
    • Compile and Run Java
  • Tokens, Expressions and Control Structures
    • Primitive data types
    • Integers
    • Floating Points
    • Characters
    • Booleans
    • User Defined Data Type
    • Declarations
    • Constants
    • Identifiers
    • Literals
    • Type Conversion and Casting
    • Variables
    • Default Variable Initialization
    • Command Line Arguments
    • Arrays of Primitive Types
    • Comment Syntax
    • Garbage Collection
    • Expressions
    • Operators
    • Arithmetic Operator
    • Bitwise and Shift Operator
    • Comparison or Relational Operators
    • Logical Operators
    • Assignment Operators
    • Ternary Operator
    • Increment and Decrement Operator
    • Control Statements
  • OOP Concepts
    • Class and Object
    • Create Class Instance
    • Method
    • Abstraction
    • Encapsulation
    • this keyword
    • Constructor
    • Pass by Value
    • Access Modifier/Control
    • Polymorphism
    • Method Overloading vs Method Overriding
    • Recursion
    • Nested and Inner Class
  • Inheritance and Packaging
    • Inheritance
    • extends Keyword
    • super Keyword
    • Object Class
    • Abstract class
    • Final Class
    • Java Package
    • Interface
  • Handling Error/ Exceptions
    • What is Exception
    • Exception Handling Keywords
    • Common Java Errors
    • User Defined Exception
    • Throwing and re-throwing Exception
    • finally Block
  • Strings
    • Java String Tutorial
  • Threads
    • Introduction
    • Create Thread
    • Thread Lifecycle
    • Thread Priority
    • Thread Synchronization
    • Inner Thread Communication
    • Thread Deadlock
  • IO and Streams
    • java.io Package
    • Files and Directories
    • Byte Stream
    • Character Stream
    • Console Input and Output
    • Serializable and Deserializable
  • Core Packages
    • java.lang Package
    • Math
    • Wrapper Classes
    • java.lang.Number
    • Double
    • Float
    • Integers
    • java.lang.Byte
    • java.lang.Short
    • java.lang.Long
    • java.lang.Character
    • java.lang.Boolean
    • java.util package
    • Vector Class
    • Stack Class
    • Dictionary Class
    • Hashtable
    • Enumeration or Enum
    • Generate Random Number
  • Holding Collection of Data
    • Arrays
    • Map
    • List
    • Set
    • Collection Interface
    • Collections Class
    • ArrayList
    • HashSet
    • TreeSet
    • Comparator
  • Java Bean
    • What is Java Bean
    • Advantages and Disadvantages of Java Bean
    • Java Beans API
    • Introspection
    • Java Bean Properties
    • Bound and Constrained Properties
    • BeanInfo Interface
    • Customizers
    • Java Beans Persistence
    • BeanDescriptor

Wrapper Classes in Java

Learn the concepts, implementation details, and practical steps with a clean developer-focused walkthrough.

Yuba Raj Kalathoki
By Yuba Raj Kalathoki
Last updated: July 1, 2026 ยท 2 min read ยท 0 Comments
Share: in X

Wrapper classes in Java are classes that allow primitive data types to be accessed as objects.

Wrapper classes in Java

There are eight wrapper classes in Java, one for each primitive data type:

  • Booleanfor boolean
  • Characterfor char
  • Bytefor byte
  • Shortfor short
  • Integerfor int
  • Longfor long
  • Floatfor float
  • Doublefor double

Wrapper classes in Java are useful when we need to treat primitives as objects, for example when we need to store them in a collection that only supports objects.

Common methods of Java wrapper classes

Following are some common methods of the wrapper classes:

valueOf()

This method returns a wrapper object that contains the value of the specified primitive. For example:

int primitiveInt = 10;
Integer wrapperInt = Integer.valueOf(primitiveInt);

parseXXX()

These methods parse a string and return the corresponding primitive value. For example:

String strInt = "123";
int primitiveInt = Integer.parseInt(strInt);

XXXValue()

These methods return the primitive value of the wrapper object. For example:

Integer wrapperInt = new Integer(123);
int primitiveInt = wrapperInt.intValue();

compareTo()

This method compares the value of the wrapper object to the value of another wrapper object or a primitive. It returns a negative integer if the value is less, a positive integer if the value is greater, and 0 if the values are equal. For example:

Integer wrapperInt1 = new Integer(123);
Integer wrapperInt2 = new Integer(456);
int result = wrapperInt1.compareTo(wrapperInt2);  // result is -1

equals()

This method compares the value of the wrapper object to the value of another object, and returns true if they are equal, and false otherwise. For example:

Integer wrapperInt1 = new Integer(123);
Integer wrapperInt2 = new Integer(123);
boolean result = wrapperInt1.equals(wrapperInt2);  // result is true

toString()

This method returns a string representation of the wrapper object. For example:

Integer wrapperInt = new Integer(123);
String str = wrapperInt.toString();  // str is "123"

Related Posts:

  • Primitive data types in Java
  • Character data type in Java
  • java.lang.Character Class in Java
  • Control Statements in Java
  • Literals in Java
  • Integers In Java
Tags:javalanguage-fundamentals
Was this article helpful?
โ† Previous ArticleJComboBox in Java Swing
Next Article โ†’How to use JList in Java Swing

Recent Posts

  • How to implement Passwordless Authentication in Spring Boot: A Step-by-Step Guide
  • How to Use AWS CloudFront Signed URLs in Spring Boot?
  • How to Fix SSH Agent Forwarding on macOS: The Ultimate Guide for Developers
  • How to Read AWS Secrets Manager in Spring Boot (Step-by-Step)
  • How to Fix “Public Key Retrieval is not allowed” MySQL JDBC Error
CoderSathi

Your go-to resource for Java, Spring Boot, Microservices, AWS, and modern development tutorials.

Linkedin

Quick Links

  • About
  • Contact

Popular Topics

  • Java
  • Spring Boot
  • AWS
  • DevOps
  • MongoDB
  • Linux
  • Git
  • How to
ยฉ 2026 CoderSathi. All rights reserved. Privacy Policy ยท Sitemap