File tree Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Expand file tree Collapse file tree 1 file changed +40
-0
lines changed Original file line number Diff line number Diff line change 1+ import java .util .Scanner ;
2+
3+ public class Wrappers {
4+ /*
5+ Wrapper Class is used for converting a primitive into Object Datatype
6+ and Object into Primitive.
7+ */
8+ public static void main (String [] args ) {
9+ Scanner scan = new Scanner (System .in );
10+ //primitive type of value
11+ int value = scan .nextInt ();
12+ long bigValue = scan .nextLong ();
13+ char ch = scan .next ().charAt (0 );
14+
15+ //Converting this data into Object data (It is called AutoBoxing)
16+ Integer objValue = new Integer (value );//int to Integer conversion explicitly
17+ //You may simple use
18+ Integer ObjValue = value ;
19+ Long BigValue = bigValue ;
20+ Character character = ch ;
21+
22+ //Object Data
23+ Integer num = 50 ;
24+ Character chars = 'B' ;
25+ Long Values = 64854858L ;
26+ Float num1 = 34.457F ;
27+
28+ ///Converting Object to Primitive (It is Called UnBoxing)
29+ int newNumber = num .intValue ();//Converting Integer to int explicitly
30+ //You may simple use
31+ int newNum = num ;
32+ char chars1 = chars ;
33+ long values1 = Values ;
34+ float num2 = num1 ;
35+
36+ System .out .println ("int Value:\s " +value +"\t " +"Integer Object value:\s " +ObjValue );
37+ System .out .println ("long Value:\s " +bigValue +"\t " +"Long Object Value:\s " +BigValue );
38+ System .out .println ("char Value:\s " +ch +"\t " +"Character Object Value:\s " +character );
39+ }
40+ }
You can’t perform that action at this time.
0 commit comments