Wrapper Classes - AP Computer Science A

  1. What is the wrapper class for the primitive type boolean?
    Boolean. Direct correspondence between boolean primitive and Boolean wrapper.
  2. Identify unboxing in: int num = new Integer(10);
    Integer object is unboxed to int. Wrapper object is automatically unwrapped to primitive type.
  3. How do you convert an Integer object to int?
    IntegerObject.intValue(). Returns primitive int value from wrapper object.
  4. Which method converts a Double object to double?
    DoubleObject.doubleValue(). Returns primitive double value from wrapper object.
  5. 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.
  6. What is the result of Character.toUpperCase('a')?
    'A'. Converts lowercase 'a' to uppercase 'A'.
  7. How do you get the int value from a String '123'?
    Integer.parseInt("123"). Parses string to extract integer value.
  8. Which method converts a String 'true' to a boolean?
    Boolean.parseBoolean("true"). Parses string to extract boolean value.
  9. Which method converts String '5' to Integer?
    Integer.valueOf("5"). Creates Integer wrapper object from string representation.
  10. Convert double 3.14 to its wrapper class object.
    Double.valueOf(3.14). Uses valueOf() to create wrapper object from primitive.
  11. Find the error: Integer i = new Integer("abc");
    Throws NumberFormatException. Invalid string format cannot be converted to number.
  12. How do you convert Boolean object to String?
    BooleanObject.toString(). Converts Boolean object to its string representation.
  13. Identify the wrapper class for the primitive type double.
    Double. Direct correspondence between double primitive and Double wrapper.
  14. Which wrapper class has the method parseShort(String)?
    Short. Short wrapper class provides parseShort() static method.
  15. How do you convert a String '3.14' to double?
    Double.parseDouble("3.14"). Parses string to extract double value.
  16. What method converts float to Float wrapper object?
    Float.valueOf(float). Creates Float wrapper object from primitive float.
  17. What is autoboxing in Java?
    Automatic conversion of primitive to wrapper class. Java automatically wraps primitives when needed.
  18. Which method returns the byte value of an Integer?
    IntegerObject.byteValue(). Converts Integer to byte primitive type.
  19. What is the result of Boolean.compare(true, false)?
    1. Returns positive since true is greater than false.
  20. What is unboxing in Java?
    Automatic conversion of wrapper class to primitive. Java automatically unwraps wrapper objects when needed.
  21. How do you convert Integer to String?
    Integer.toString(). Converts Integer wrapper object to string representation.
  22. Which method returns the int value of a Byte object?
    ByteObject.intValue(). Converts Byte wrapper to int primitive type.
  23. What is the wrapper class for primitive type byte?
    Byte. Direct correspondence between byte primitive and Byte wrapper.
  24. Convert int 5 to its wrapper class object.
    Integer.valueOf(5). Uses valueOf() to create wrapper object from primitive.
  25. What does Long.parseLong("123456789") return?
    123456789L. Parses string to extract long value.
  26. Which wrapper class corresponds to the primitive type char?
    Character. Direct correspondence between char primitive and Character wrapper.
  27. What is the result of Integer.compare(4, 5)?
    -1. Returns negative since 4 is less than 5.
  28. Which method checks if a Character is a digit?
    Character.isDigit(). Checks if character represents a numeric digit (0-9).
  29. 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.
  30. Identify the wrapper class for the primitive type float.
    Float. Direct correspondence between float primitive and Float wrapper.
  31. Which wrapper class represents the primitive type int?
    Integer. Direct correspondence between int primitive and Integer wrapper.
  32. What method converts a Character object to char?
    CharacterObject.charValue(). Returns primitive char value from wrapper object.
  33. How do you convert '123.45' to Float?
    Float.parseFloat("123.45"). Parses string to extract float value as Float object.

Study these flashcards