-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWrapperClassDemo.java
More file actions
55 lines (45 loc) · 2.32 KB
/
WrapperClassDemo.java
File metadata and controls
55 lines (45 loc) · 2.32 KB
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
51
52
53
54
55
public class WrapperClassDemo {
public static void main(String[] args) {
// Demonstrating Integer wrapper class methods
Integer intObj = Integer.valueOf(42); // Boxing
int intValue = intObj.intValue(); // Unboxing
System.out.println("Integer value: " + intValue);
// Parsing a string to an integer
String intString = "123";
int parsedInt = Integer.parseInt(intString);
System.out.println("Parsed Integer: " + parsedInt);
// Comparing two Integer objects
Integer anotherIntObj = Integer.valueOf(42);
System.out.println("Comparison: " + intObj.compareTo(anotherIntObj));
// Demonstrating Double wrapper class methods
Double doubleObj = Double.valueOf(3.14);
double doubleValue = doubleObj.doubleValue();
System.out.println("Double value: " + doubleValue);
// Parsing a string to a double
String doubleString = "3.14159";
double parsedDouble = Double.parseDouble(doubleString);
System.out.println("Parsed Double: " + parsedDouble);
// Checking if a value is infinite or NaN
System.out.println("Is Infinite: " + doubleObj.isInfinite());
System.out.println("Is NaN: " + doubleObj.isNaN());
// Demonstrating Character wrapper class methods
Character charObj = Character.valueOf('A');
char charValue = charObj.charValue();
System.out.println("Character value: " + charValue);
// Checking character properties
System.out.println("Is Letter: " + Character.isLetter(charValue));
System.out.println("Is Digit: " + Character.isDigit(charValue));
// Demonstrating Boolean wrapper class methods
Boolean boolObj = Boolean.valueOf(true);
boolean boolValue = boolObj.booleanValue();
System.out.println("Boolean value: " + boolValue);
// Parsing a string to a boolean
String boolString = "true";
boolean parsedBoolean = Boolean.parseBoolean(boolString);
System.out.println("Parsed Boolean: " + parsedBoolean);
// Demonstrating static methods
System.out.println("Integer Max Value: " + Integer.MAX_VALUE);
System.out.println("Double Min Value: " + Double.MIN_VALUE);
System.out.println("Character Lowercase: " + Character.toLowerCase('B'));
}
}