Wrapper Example Java Program
Definition
A wrapper class is a class that encapsulates types so that those types can be used to create object instances and methods in another class that need those types.
Syntax
Integer variable-name = new Integer(10);
Wrapper Example Program
public class WrapperExample {
public static void main(String[] args) {
int primitiveInteger = 500;
System.out.println("Primitive Integer : " + primitiveInteger);
Integer wrapperInteger = Integer.valueOf(primitiveInteger);
System.out.println("After assigning this value in Wrapper Integer : " + wrapperInteger);
primitiveInteger = wrapperInteger.intValue();
System.out.println("Again assigning this value in Primitive Integer : " + primitiveInteger);
String integerString = "1000";
System.out.println("String to be converted to integer : " + integerString);
System.out.println("Converting String to integer : " + Integer.parseInt(integerString));
}
}
Sample Output
Primitive Integer : 500
After assigning this value in Wrapper Integer : 500
Again assigning this value in Primitive Integer : 500
String to be converted to integer : 1000
Converting String to integer : 1000
Java Collection Programs
- Linked List Example Java Program
- ArrayList Example Java Program
- HashSet Example Java Program
- Clear an Arraylist Example Java Program
- Reversing an ArrayList Example Java Program
- Linked HashSet Example Java Program
- HashMap Example Java Program
- Set Value in ArrayList Example Java Program
- Linked HashMap Example Java Program
- Remove Element from ArrayList Example Java Program
- Identity HashMap Example Java Program
- TreeMap Example Java Program
- TreeSet Example Java Program
- Finding Duplicates in Array Using TreeSet Java Example Program
- HashTable Example Java Program
- EnumSet Example Java Program
- Enum Map Example Java Program
- Wrapper Example Java Program
- Un Modifiable Wrapper Example Java Program
- Iterator Interface Example Java Program
- Sorted Map Interface Example Java Program
- Sorted Set Interface Example Java Program
Read More Articles
- Multiple Inheritance Using Interface Example Java Program
- Single Inheritance Example Java Program
- Multilevel Inheritance Example Java Program
- Hierarchical Inheritance Example Java Program
- Find all Substrings of a given string Example Java Program
- Create Matrix Example Java Program
- Sum Of Three Numbers Example Java Program
- Heap Sort Example Java Program
- Twin Prime Example Java Program
- Compile Time Polymorphism Example Java Program