Wrapper methods programs
Here are Java programs based on wrapper classes and their methods, showing only input and output:
✅ 1. Convert String to int
Input: "123"
Output: 133
String s = "123";
int num = Integer.parseInt(s);
System.out.println(num + 10);
✅ 2. String to Integer object
Input: "456"
Output: 912
String s = "456";
Integer obj = Integer.valueOf(s);
System.out.println(obj * 2);
✅ 3. Check if char is digit
Input: '5'
Output: It's a digit.
char c = '5';
if(Character.isDigit(c)) {
System.out.println("It's a digit.");
}
✅ 4. Check if char is letter
Input: 'a'
Output: true
char ch = 'a';
System.out.println(Character.isLetter(ch));
✅ 5. Convert upper to lower
Input: 'A'
Output: 'a'
char upper = 'A';
System.out.println(Character.toLowerCase(upper));
✅ 6. Convert lower to upper
Input: 'm'
Output: 'M'
char lower = 'm';
System.out.println(Character.toUpperCase(lower));
✅ 7. Compare integers
Input: 10
, 20
Output: -1
System.out.println(Integer.compare(10, 20));
✅ 8. Get MAX, MIN
Output:
Max: 2147483647
Min: -2147483648
System.out.println("Max: " + Integer.MAX_VALUE);
System.out.println("Min: " + Integer.MIN_VALUE);
✅ 9. int to String
Input: 100
Output: 100 is now a String.
int n = 100;
String str = String.valueOf(n);
System.out.println(str + " is now a String.");
✅ 10. Parse boolean
Input: "true"
Output: true
String s = "true";
boolean b = Boolean.parseBoolean(s);
System.out.println(b);
✅ 11. Parse float from string
Input: "45.67"
Output: 50.67
String price = "45.67";
float f = Float.parseFloat(price);
System.out.println(f + 5);
✅ 12. Long from string
Input: "9876543210"
Output: Mobile: 9876543210
String val = "9876543210";
Long mobile = Long.valueOf(val);
System.out.println("Mobile: " + mobile);
✅ 13. ASCII value
Input: 'A'
Output: ASCII: 65
char ch = 'A';
int ascii = (int) ch;
System.out.println("ASCII: " + ascii);
✅ 14. isUpperCase
Input: 'G'
Output: true
char c = 'G';
System.out.println(Character.isUpperCase(c));
✅ 15. Use doubleValue
Input: "123.456"
Output: 133.456
Double d = Double.valueOf("123.456");
System.out.println(d.doubleValue() + 10.0);
✅ 16. Check lowercase
Input: 'z'
→ Output: true
System.out.println(Character.isLowerCase('z'));
✅ 17. Check whitespace
Input: ' '
→ Output: true
System.out.println(Character.isWhitespace(' '));
✅ 18. Double to String
Input: 12.5
→ Output: "12.5"
double d = 12.5;
String s = Double.toString(d);
System.out.println(s);
✅ 19. Autobox int to Integer
Input: 99
→ Output: Integer: 99
int x = 99;
Integer obj = x;
System.out.println("Integer: " + obj);
✅ 20. Unbox Integer to int
Input: 42
→ Output: int: 42
Integer val = 42;
int i = val;
System.out.println("int: " + i);
✅ 21. Character get numeric value
Input: '5'
→ Output: 5
System.out.println(Character.getNumericValue('5'));
✅ 22. Float to int
Input: "12.9"
→ Output: 12
float f = Float.parseFloat("12.9");
int i = (int) f;
System.out.println(i);
✅ 23. Check alphabet
Input: '9'
→ Output: false
System.out.println(Character.isAlphabetic('9'));
✅ 24. Long parse
Input: "123456"
→ Output: 124456
long l = Long.parseLong("123456");
System.out.println(l + 1000);
✅ 25. Boolean valueOf
Input: "false"
→ Output: false
Boolean b = Boolean.valueOf("false");
System.out.println(b);
✅ 26. Byte from string
Input: "120"
→ Output: 130
byte b = Byte.parseByte("120");
System.out.println((byte)(b + 10));
✅ 27. Short from string
Input: "2000"
→ Output: 3000
short s = Short.parseShort("2000");
System.out.println((short)(s + 1000));
✅ 28. Compare Double
Input: 12.3
, 15.6
→ Output: -1
System.out.println(Double.compare(12.3, 15.6));
✅ 29. Boolean logical operation
Input: "true"
& "false"
→ Output: false
Boolean b1 = Boolean.valueOf("true");
Boolean b2 = Boolean.valueOf("false");
System.out.println(b1 && b2);
✅ 30. Char to int using wrapper
Input: 'B'
→ Output: 66
char ch = 'B';
System.out.println((int) ch);
✅ 31. Character.isDefined
Input: '%'
→ Output: true
System.out.println(Character.isDefined('%'));
✅ 32. Character.isISOControl
Input: '\n'
→ Output: true
System.out.println(Character.isISOControl('\n'));
✅ 33. Boolean parse from mixed case
Input: "TrUe"
→ Output: true
System.out.println(Boolean.parseBoolean("TrUe"));
✅ 34. Integer.toHexString
Input: 255
→ Output: ff
System.out.println(Integer.toHexString(255));
✅ 35. Integer.toBinaryString
Input: 10
→ Output: 1010
System.out.println(Integer.toBinaryString(10));
✅ 36. Integer.toOctalString
Input: 64
→ Output: 100
System.out.println(Integer.toOctalString(64));
✅ 37. CompareTo for Integer
Input: 20
, 10
→ Output: 1
Integer a = 20;
Integer b = 10;
System.out.println(a.compareTo(b));
✅ 38. Float.compare
Input: 5.4
, 5.4
→ Output: 0
System.out.println(Float.compare(5.4f, 5.4f));
✅ 39. Convert char to string
Input: 'x'
→ Output: x
char ch = 'x';
String s = Character.toString(ch);
System.out.println(s);
✅ 40. Character.isTitleCase
Input: 'ล'
→ Output: true
System.out.println(Character.isTitleCase('ล'));
✅ 41. Check uppercase
Input: 'D'
→ Output: true
System.out.println(Character.isUpperCase('D'));
✅ 42. Parse negative int
Input: "-89"
→ Output: -79
int val = Integer.parseInt("-89");
System.out.println(val + 10);
✅ 43. Character.isSurrogate
Input: '\uD800'
→ Output: true
System.out.println(Character.isSurrogate('\uD800'));
✅ 44. Convert int to float
Input: 25
→ Output: 25.0
int i = 25;
Float f = (float) i;
System.out.println(f);
✅ 45. Convert float to double
Input: 5.2f
→ Output: 5.2
float f = 5.2f;
Double d = (double) f;
System.out.println(d);
✅ 46. Wrapper null check
Output: Wrapper is null
Integer i = null;
if(i == null) System.out.println("Wrapper is null");
✅ 47. Wrapper to String then concat
Input: 200
→ Output: 200Rs
Integer val = 200;
String price = val.toString() + "Rs";
System.out.println(price);
✅ 48. Parse double scientific
Input: "1.2e2"
→ Output: 120.0
double d = Double.parseDouble("1.2e2");
System.out.println(d);
✅ 49. Character.getType
Input: 'A'
→ Output: 1
System.out.println(Character.getType('A'));
✅ 50. Byte value check
Input: Byte.MAX_VALUE
→ Output: 127
System.out.println(Byte.MAX_VALUE);
✅ 51. Boolean XOR
Input: true
, false
→ Output: true
System.out.println(true ^ false);
✅ 52. Short.MAX_VALUE
Output: 32767
System.out.println(Short.MAX_VALUE);
✅ 53. Integer.reverse
Input: 123
→ Output: -1073741824
System.out.println(Integer.reverse(123));
✅ 54. Parse boolean with random case
Input: "TRUE"
→ Output: true
System.out.println(Boolean.parseBoolean("TRUE"));
✅ 55. Integer.byteValue
Input: 130
→ Output: -126
Integer i = 130;
System.out.println(i.byteValue());
✅ 56. Float intValue
Input: 9.75f
→ Output: 9
Float f = 9.75f;
System.out.println(f.intValue());
✅ 57. Wrapper equals
Input: 100
, 100
→ Output: true
Integer a = 100, b = 100;
System.out.println(a.equals(b));
✅ 58. ParseInt with base
Input: "A"
, base 16 → Output: 10
System.out.println(Integer.parseInt("A", 16));
✅ 59. Double.NaN check
Output: true
System.out.println(Double.isNaN(0.0/0));
✅ 60. Double infinity check
Input: 1.0/0
→ Output: true
System.out.println(Double.isInfinite(1.0/0));
✅ 61. Integer.highestOneBit
Input: 18
→ Output: 16
System.out.println(Integer.highestOneBit(18));
✅ 62. Integer.lowestOneBit
Input: 18
→ Output: 2
System.out.println(Integer.lowestOneBit(18));
✅ 63. Long.bitCount
Input: 15
→ Output: 4
System.out.println(Long.bitCount(15));
✅ 64. Integer.signum
Input: -10
→ Output: -1
System.out.println(Integer.signum(-10));
✅ 65. Double.compare NaN
Input: Double.NaN, 5.0
→ Output: 1
System.out.println(Double.compare(Double.NaN, 5.0));
✅ 66. Convert char to int using wrapper
Input: '8'
Output: 8
char c = '8';
int n = Character.getNumericValue(c);
System.out.println(n);
✅ 67. Check if space is whitespace
Input: ' '
Output: true
System.out.println(Character.isWhitespace(' '));
✅ 68. Byte parse from String
Input: "127"
Output: 127
String val = "127";
byte b = Byte.parseByte(val);
System.out.println(b);
✅ 69. Short parse from String
Input: "32000"
Output: 32000
String s = "32000";
short sh = Short.parseShort(s);
System.out.println(sh);
✅ 70. Use Integer.reverse()
Input: 10
Output: 1431655765
System.out.println(Integer.reverse(10));
✅ 71. Use Double.toHexString()
Input: 12.25
Output: 0x1.8p3
System.out.println(Double.toHexString(12.25));
✅ 72. Parse Boolean with "TRUE"
Input: "TRUE"
Output: true
System.out.println(Boolean.parseBoolean("TRUE"));
✅ 73. Use Long.highestOneBit()
Input: 10L
Output: 8
System.out.println(Long.highestOneBit(10L));
✅ 74. Float compare
Input: 10.5f
, 20.3f
Output: -1
System.out.println(Float.compare(10.5f, 20.3f));
✅ 75. Character.isDefined()
Input: 'A'
Output: true
System.out.println(Character.isDefined('A'));
✅ 76. Character.getType()
Input: '9'
Output: 9
(TYPE_DECIMAL_DIGIT_NUMBER)
System.out.println(Character.getType('9'));
✅ 77. Boolean.toString(false)
Input: false
Output: "false"
System.out.println(Boolean.toString(false));
✅ 78. Byte.MAX_VALUE
Output: 127
System.out.println(Byte.MAX_VALUE);
✅ 79. Byte.MIN_VALUE
Output: -128
System.out.println(Byte.MIN_VALUE);
✅ 80. Double.isInfinite()
Input: 1.0/0.0
Output: true
double d = 1.0 / 0.0;
System.out.println(Double.isInfinite(d));
✅ 81. Float.isNaN()
Input: 0.0f/0.0f
Output: true
float f = 0.0f / 0.0f;
System.out.println(Float.isNaN(f));
✅ 82. Character.toTitleCase()
Input: 'g'
Output: G
System.out.println(Character.toTitleCase('g'));
✅ 83. Character.digit()
Input: 'F'
, radix 16
Output: 15
System.out.println(Character.digit('F', 16));
✅ 84. Boolean logical XOR
Input: true
, false
Output: true
System.out.println(Boolean.logicalXor(true, false));
✅ 85. Integer.divideUnsigned()
Input: 10
, 3
Output: 3
System.out.println(Integer.divideUnsigned(10, 3));
✅ 86. Integer.remainderUnsigned()
Input: 10
, 3
Output: 1
System.out.println(Integer.remainderUnsigned(10, 3));
✅ 87. Integer.toUnsignedString()
Input: -1
Output: 4294967295
System.out.println(Integer.toUnsignedString(-1));
✅ 88. Long.toBinaryString()
Input: 20L
Output: 10100
System.out.println(Long.toBinaryString(20L));
✅ 89. Character.isSurrogate()
Input: 'a'
Output: false
System.out.println(Character.isSurrogate('a'));
✅ 90. Double.equals()
Input: 10.0
, 10.0
Output: true
Double d1 = 10.0, d2 = 10.0;
System.out.println(d1.equals(d2));
✅ 91. Integer.toOctalString()
Input: 100
Output: 144
System.out.println(Integer.toOctalString(100));
✅ 92. Integer.toHexString()
Input: 255
Output: ff
System.out.println(Integer.toHexString(255));
✅ 93. Long.rotateLeft()
Input: 5
, 2
Output: 20
System.out.println(Long.rotateLeft(5L, 2));
✅ 94. Long.rotateRight()
Input: 20
, 2
Output: 5
System.out.println(Long.rotateRight(20L, 2));
✅ 95. Use Float.hashCode()
Input: 3.14f
Output: (some int hash)
System.out.println(Float.hashCode(3.14f));
✅ 96. Use Double.hashCode()
Input: 5.5
Output: (some int hash)
System.out.println(Double.hashCode(5.5));
✅ 97. Use Boolean.hashCode()
Input: true
Output: 1231
System.out.println(Boolean.hashCode(true));
✅ 98. Character.charCount()
Input: 0x1F600
Output: 2
System.out.println(Character.charCount(0x1F600));
✅ 99. Character.isISOControl()
Input: \u0009
(tab)
Output: true
System.out.println(Character.isISOControl('\u0009'));
✅ 100. Convert primitive double to Double object
Input: 50.5
Output: 50.5
double x = 50.5;
Double d = Double.valueOf(x);
System.out.println(d);
Comments
Post a Comment