-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathD4-4.txt
50 lines (42 loc) · 1.9 KB
/
D4-4.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
class WrapperClassTester {
public static void main(String[] args) {
int i = 45;//primitive data int
Integer integer = new Integer(i);// Integer wrapper class instantiation
int i2 = integer.intValue();// unwrapping primitive data int from wrapper object
Integer integer2 = new Integer("23");
// all wrapper class except Character can take String in argument
System.out.println(integer2);
Integer intObj1 = new Integer(25);
Integer intObj2 = new Integer("25");
Integer intObj3 = new Integer(35);
//compareTo demo
System.out.println("Comparing using compareTo obj1 and obj2: " + intObj1.compareTo(intObj2));
System.out.println("Comparing using compareTo obj1 and obj3: " + intObj1.compareTo(intObj3));
// Equals demo
System.out.println("Comparing using compareTo obj1 and obj2: " + intObj1.equals(intObj2));
System.out.println("Comparing using compareTo obj1 and obj3: " + intObj1.equals(intObj3));
Float f1 = new Float("2.25f");
Float f2 = new Float("20.43f");
Float f3 = new Float(2.25f);
System.out.println("Comparing using compare f1 and f2: " + Float.compare(f1,f2));
System.out.println("Comparing using compare f1 and f3: " + Float.compare(f1,f3));
// Addition of Integer with Float
Float f = intObj1.floatValue() + f1;
System.out.println("Addition of intObj1 and f1: "+ intObj1 + "+" + f1 + "=" + f);
int x = Integer.parseInt("34");
System.out.println(x);
double y = Double.parseDouble("34.7");
System.out.println(y);
}
}
Output:
23
Comparing using compareTo obj1 and obj2: 0
Comparing using compareTo obj1 and obj3: -1
Comparing using compareTo obj1 and obj2: true
Comparing using compareTo obj1 and obj3: false
Comparing using compare f1 and f2: -1
Comparing using compare f1 and f3: 0
Addition of intObj1 and f1: 25+2.25=27.25
34
34.7