Wrapper Classes - AP Computer Science A
- What is the wrapper class for the primitive type boolean?
- Boolean. Direct correspondence between boolean primitive and Boolean wrapper.
- Identify unboxing in: int num = new Integer(10);
- Integer object is unboxed to int. Wrapper object is automatically unwrapped to primitive type.
- How do you convert an Integer object to int?
- IntegerObject.intValue(). Returns primitive int value from wrapper object.
- Which method converts a Double object to double?
- DoubleObject.doubleValue(). Returns primitive double value from wrapper object.
- What is the purpose of a wrapper class in Java?
- To provide object equivalents for primitive data types. Allows primitives to be used in collections and as objects.
- What is the result of Character.toUpperCase('a')?
- 'A'. Converts lowercase 'a' to uppercase 'A'.
- How do you get the int value from a String '123'?
- Integer.parseInt("123"). Parses string to extract integer value.
- Which method converts a String 'true' to a boolean?
- Boolean.parseBoolean("true"). Parses string to extract boolean value.
- Which method converts String '5' to Integer?
- Integer.valueOf("5"). Creates Integer wrapper object from string representation.
- Convert double 3.14 to its wrapper class object.
- Double.valueOf(3.14). Uses valueOf() to create wrapper object from primitive.
- Find the error: Integer i = new Integer("abc");
- Throws NumberFormatException. Invalid string format cannot be converted to number.
- How do you convert Boolean object to String?
- BooleanObject.toString(). Converts Boolean object to its string representation.
- Identify the wrapper class for the primitive type double.
- Double. Direct correspondence between double primitive and Double wrapper.
- Which wrapper class has the method parseShort(String)?
- Short. Short wrapper class provides parseShort() static method.
- How do you convert a String '3.14' to double?
- Double.parseDouble("3.14"). Parses string to extract double value.
- What method converts float to Float wrapper object?
- Float.valueOf(float). Creates Float wrapper object from primitive float.
- What is autoboxing in Java?
- Automatic conversion of primitive to wrapper class. Java automatically wraps primitives when needed.
- Which method returns the byte value of an Integer?
- IntegerObject.byteValue(). Converts Integer to byte primitive type.
- What is the result of Boolean.compare(true, false)?
- 1. Returns positive since true is greater than false.
- What is unboxing in Java?
- Automatic conversion of wrapper class to primitive. Java automatically unwraps wrapper objects when needed.
- How do you convert Integer to String?
- Integer.toString(). Converts Integer wrapper object to string representation.
- Which method returns the int value of a Byte object?
- ByteObject.intValue(). Converts Byte wrapper to int primitive type.
- What is the wrapper class for primitive type byte?
- Byte. Direct correspondence between byte primitive and Byte wrapper.
- Convert int 5 to its wrapper class object.
- Integer.valueOf(5). Uses valueOf() to create wrapper object from primitive.
- What does Long.parseLong("123456789") return?
- 123456789L. Parses string to extract long value.
- Which wrapper class corresponds to the primitive type char?
- Character. Direct correspondence between char primitive and Character wrapper.
- What is the result of Integer.compare(4, 5)?
- -1. Returns negative since 4 is less than 5.
- Which method checks if a Character is a digit?
- Character.isDigit(). Checks if character represents a numeric digit (0-9).
- Identify autoboxing in: List<Integer> list = new ArrayList<>(); list.add(5);
- int 5 is autoboxed to Integer. Primitive int is automatically wrapped to fit Integer collection.
- Identify the wrapper class for the primitive type float.
- Float. Direct correspondence between float primitive and Float wrapper.
- Which wrapper class represents the primitive type int?
- Integer. Direct correspondence between int primitive and Integer wrapper.
- What method converts a Character object to char?
- CharacterObject.charValue(). Returns primitive char value from wrapper object.
- How do you convert '123.45' to Float?
- Float.parseFloat("123.45"). Parses string to extract float value as Float object.