Wrapper Class Methods, Character Tests and Autoboxing in Java (ICSE Class 10)
Updated 17 October 2026 · Fact-checked
Every primitive type has a wrapper class (int - Integer, double - Double, char - Character, boolean - Boolean and so on) that wraps its value in an object. parseInt, parseLong, parseFloat and parseDouble convert a String to a number; Character methods such as isDigit, isLetter, isUpperCase, toUpperCase and toLowerCase test or convert one char. Autoboxing converts a primitive to its wrapper object automatically; unboxing does the reverse.
Boxing and unboxing switch between primitive and object; parseInt turns valid text into a number, but bad text stops the program with an exception.
Illustration drawn for QuestionBuddy.
Understand Wrapper Class Methods, Character Tests and Autoboxing
Wrapper classes. They turn a primitive into an object and carry useful methods: byte - Byte, short - Short, int - Integer, long - Long, float - Float, double - Double, char - Character, boolean - Boolean. They are in java.lang, so no import is needed.
Parse methods (String to number) from the syllabus:
int Integer.parseInt(String s):parseInt("25")is 25long Long.parseLong(String s),float Float.parseFloat(String s),double Double.parseDouble(String s):parseDouble("2.5")is 2.5
If the text is not a valid number for that type ("12a", "4.5" for parseInt, an empty string) the program stops at run time with a NumberFormatException. The text "25" is a String; "25" + 5 joins to "255", while Integer.parseInt("25") + 5 adds to 30.
Character test methods (boolean): isDigit(ch), isLetter(ch), isLetterOrDigit(ch), isLowerCase(ch), isUpperCase(ch), isWhitespace(ch). Examples: Character.isLetterOrDigit('_') is false; Character.isWhitespace(' ') is true.
Character conversion methods (char): Character.toLowerCase(ch) and Character.toUpperCase(ch) return a char; characters that are not letters come back unchanged. Used with a loop over s.charAt(i) they count or change characters of a string.
Autoboxing and unboxing. *Autoboxing*: the compiler converts a primitive to its wrapper object automatically: Integer a = 10;. *Unboxing*: the wrapper object is converted back to the primitive: int b = a;. In an expression like a + 3, a is unboxed and the result is an int.
Class as a composite type. Wrapper classes and String are examples of classes used as types; the variable holds a reference to an object, unlike primitives.
Only the wrapper methods listed above are in the syllabus.
Wrapper Class Methods, Character Tests and Autoboxing: key facts
- Wrapper classes
int Integer long Long float Float double Double char Character boolean Boolean byte Byte short Short - Capital first letter; Integer and Character are spelt in full.
- Parse methods
Integer.parseInt String Long.parseLong String Float.parseFloat String Double.parseDouble String - Invalid text gives NumberFormatException at run time.
- Character tests
- isDigit
- isLetter
- isLetterOrDigit
- isLowerCase
- isUpperCase
- isWhitespace (each takes a char, returns boolean)
- Called as Character.isDigit(ch).
- Character conversion and boxing
- toLowerCase(ch)
- toUpperCase(ch)
- Autoboxing: primitive to object
- Unboxing: object to primitive
- Non-letters are unchanged by toUpperCase.
How to answer Wrapper Class Methods, Character Tests and Autoboxing questions
Use this routine for wrapper-method output questions.
- 1Decide whether the argument is a String (parse methods) or a char (Character methods).
- 2Evaluate the wrapper call and note its return type (int, double, boolean or char).
- 3Remember that + joins when a String is involved and adds when both sides are numbers.
- 4For char arithmetic, convert to the ASCII number first.
- 5If the text is not a valid number, state the run-time NumberFormatException.
Wrapper Class Methods, Character Tests and Autoboxing in real life
The idea, met in an everyday situation. Answer the question in your own words, then compare with the model answer. The one-line hook is what to remember.
Parsing typed marks
Suppose a form field gives marks as text such as "86" and the program must add 4 grace marks.
What is the result of "86" + 4 and of Integer.parseInt("86") + 4?
Try it first, then show the solutionSolution
- "86" + 4 joins the text: 864.
- parseInt gives the number 86, so 86 + 4 = 90.
Answer: "864" for the first and 90 for the second.
Memory hook: Parse first, then add.
Tricks to remember Wrapper Class Methods, Character Tests and Autoboxing
Short memory aids. Say each one aloud once, then use it on a question the same day.
parse + Type
parseInt, parseLong, parseFloat, parseDouble: the type name follows parse.
Use it when: Choosing a parse method.
is... asks, to... changes
Methods starting with is answer true or false; methods starting with to return a changed char.
Use it when: Return types of Character methods.
Box in, box out
Autoboxing puts a primitive in a box (object); unboxing takes it out.
Use it when: Definitions.
Wrapper Class Methods, Character Tests and Autoboxing: solved examples
Ordered from board level to HOTS. Try each one before you open the solution.
Example 1: Wrapper classes · 3 marks · Short answerBoard level
Write the wrapper class of each primitive type: int, char, double, boolean, long, float.
Try it first, then show the solutionSolution
- int - Integer, char - Character. (1 mark)
- double - Double, boolean - Boolean. (1 mark)
- long - Long, float - Float. (1 mark)
Answer: Integer, Character, Double, Boolean, Long, Float.
Example 2: Parse versus join · 3 marks · Short answerHarder board level
Write the output:
String s = "25";
int n = Integer.parseInt(s) + 5;
String t = s + 5;
double d = Double.parseDouble("2.5") * 2;
System.out.println(n + " " + t + " " + d);Try it first, then show the solutionSolution
- parseInt(s) is 25, so n = 25 + 5 = 30. (1 mark)
- t = s + 5 joins the text: "255". (1 mark)
- d = 2.5 * 2 = 5.0. The output is 30 255 5.0. (1 mark)
Answer: 30 255 5.0
Example 3: Counting character types · 3 marks · Short answerHarder board level
Write the output:
String w = "A1b2 c3!";
int L = 0, D = 0, W = 0, O = 0;
for (int i = 0; i < w.length(); i++) {
char c = w.charAt(i);
if (Character.isLetter(c)) L++;
else if (Character.isDigit(c)) D++;
else if (Character.isWhitespace(c)) W++;
else O++;
}
System.out.println(L + " " + D + " " + W + " " + O);Try it first, then show the solutionSolution
- The eight characters are A, 1, b, 2, space, c, 3, !. (1 mark)
- Letters: A, b, c = 3; digits: 1, 2, 3 = 3. (1 mark)
- Whitespace: the space = 1; other: ! = 1. Output 3 3 1 1. (1 mark)
Answer: 3 3 1 1
Example 4: Case study: toggling case and boxing · 4 marks · Case-basedHOTS / competency
A program changes the case of each letter:
String s = "Java 8";
String r = "";
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (Character.isUpperCase(c))
r = r + Character.toLowerCase(c);
else if (Character.isLowerCase(c))
r = r + Character.toUpperCase(c);
else
r = r + c;
}
System.out.println(r);
Integer a = 10;
int b = a + 3;
System.out.println(b);(i) State the output. (2)
(ii) Name the wrapper methods used. (1)
(iii) Identify the autoboxing and unboxing statements. (1)
Try it first, then show the solutionSolution
- (i) J becomes j, a becomes A, v becomes V, a becomes A, the space and 8 stay: jAVA 8. Then b = 10 + 3 = 13.
- (ii) Character.isUpperCase, Character.toLowerCase, Character.isLowerCase and Character.toUpperCase.
- (iii) Integer a = 10; is autoboxing (int to Integer). In int b = a + 3; the value of a is unboxed to int.
Answer: (i) jAVA 8 and 13 (ii) isUpperCase, toLowerCase, isLowerCase, toUpperCase (iii) Integer a = 10 (boxing); a + 3 (unboxing)
Example 5: Valid and invalid strings · 4 marks · Short answerHarder board level
State the result of each, or the error:
(i) Integer.parseInt("45")
(ii) Integer.parseInt("4.5")
(iii) Double.parseDouble("4.5")
(iv) Character.isDigit('x')
Try it first, then show the solutionSolution
- (i) 45 as an int. (1 mark)
- (ii) "4.5" is not a valid int text: NumberFormatException at run time. (1 mark)
- (iii) 4.5 as a double. (1 mark)
- (iv) x is not a digit: false. (1 mark)
Answer: (i) 45 (ii) NumberFormatException (iii) 4.5 (iv) false
Where students lose marks in Wrapper Class Methods, Character Tests and Autoboxing
The slips examiners see most often, and what to write instead.
Mistake: Writing "25" + 5 as 30
The text "25" is a String, so + joins.
Wrong working
"25" + 5 = 30
Right working
"25" + 5 = "255"; Integer.parseInt("25") + 5 = 30
Do this: Parse before adding.
Usually costs: 1 mark
Mistake: Calling the method on a variable instead of the class
The wrapper methods are called with the class name.
Wrong working
ch.isDigit()
Right working
Character.isDigit(ch)
Do this: Write Character. or Integer. first.
Usually costs: 1 mark
Mistake: Answering parseInt("4.5") as 4
Decimal text is not a valid int; the program stops with NumberFormatException.
Wrong working
Integer.parseInt("4.5") = 4
Right working
Integer.parseInt("4.5") throws NumberFormatException
Do this: Use parseDouble for decimal text.
Usually costs: 1 mark
Exam tips
- Learn the twelve methods of the syllabus list with their return types.
- Write Character.isDigit(c), not c.isDigit().
- When text and a number are combined with +, check for String first.
- Give a small example with each autoboxing and unboxing definition.
Practice questions on Wrapper Class Methods, Character Tests and Autoboxing
Write each answer on paper first. Open the hint only if you are stuck, and the answer only when you have finished.
Q1 · 1 mark · MCQBoard level
The wrapper class for the primitive type char is:
(a) Char (b) Character (c) String (d) CharacHint
Spelt in full.
Answer
(b) Character
Q2 · 1 mark · Very short answerBoard level
Which method converts the String "3.75" to a double value?
Hint
Wrapper class plus parse.
Answer
Double.parseDouble("3.75")
Q3 · 2 marks · Short answerHarder board level
Write the output:
System.out.println(Character.toUpperCase('b') + 1); System.out.println(Character.isLetter('5') + " " + Character.isLetterOrDigit('5'));(ASCII code of A is 65.)
Hint
A char plus an int is an int.
Answer
67
false trueQ4 · 3 marks · Short answerHarder board level
Define autoboxing and unboxing with one example each. What does the following display?
Integer a = 7;
int b = a + 3;
System.out.println(b);Hint
Which direction is each?
Answer
Autoboxing is the automatic conversion of a primitive to its wrapper object, e.g. Integer a = 7;. Unboxing is the automatic conversion of a wrapper object to its primitive, e.g. int c = a;. In the code a is unboxed in a + 3, so b = 10 and 10 is displayed.
Q5 · 1 mark · Assertion-reasonHOTS / competency
Assertion (A): Integer.parseInt("3.5") causes a run-time exception.
Reason (R): The text "3.5" is not a valid representation of an int.
(a) Both A and R are true and R is the correct explanation of A. (b) Both A and R are true but R is not the correct explanation of A. (c) A is true but R is false. (d) A is false but R is true.Hint
Which exception, and why?
Answer
(a) Both are true and R explains A (NumberFormatException).
Test your recall
Answer in your head or on paper first, then open the card. Pulling an answer out of memory makes it stick far better than re-reading.
1.What is the wrapper class of boolean?Show answer
Boolean
2.What does Character.isWhitespace(' ') return?Show answer
true
3.Which method converts a String to long?Show answer
Long.parseLong(String)
4.What is autoboxing?Show answer
Automatic conversion of a primitive value to its wrapper object.
5.What does Character.toUpperCase('5') return?Show answer
'5' (unchanged)
6.Which exception is thrown by parseInt("abc")?Show answer
NumberFormatException
Wrapper Class Methods, Character Tests and Autoboxing: frequently asked questions
Why do we need wrapper classes?
They let primitive values be treated as objects and provide methods such as parseInt and isDigit.
Is String a wrapper class?
No. String is a class for text; wrapper classes wrap primitive values.
Are the Character methods static?
Yes, they are called with the class name, such as Character.isLetter(ch).