Recall & Review
beginner
What is the purpose of wrapper classes in Java?
Wrapper classes provide a way to use primitive data types (like int, double) as objects. They allow primitives to be treated like objects, which is useful for collections and methods that require objects.
touch_appClick to reveal answer
beginner
How do you convert a String to an int using a wrapper method?
Use
Integer.parseInt(String s) to convert a String to an int. For example, int num = Integer.parseInt("123"); converts the string "123" to the integer 123.touch_appClick to reveal answer
intermediate
What does the method
Integer.valueOf(String s) do?It converts a String to an Integer object. Unlike
parseInt which returns a primitive int, valueOf returns an Integer object.touch_appClick to reveal answer
beginner
How can you convert a primitive int to a String using wrapper methods?
You can use
String.valueOf(int i) or Integer.toString(int i). Both return the String representation of the int.touch_appClick to reveal answer
intermediate
What is the difference between
parseXxx() and valueOf() methods in wrapper classes?parseXxx() methods return primitive types (like int, double), while valueOf() methods return wrapper objects (like Integer, Double).touch_appClick to reveal answer
Which method converts a String to a primitive int?
Which method returns an Integer object from a String?
How do you convert a primitive int to a String?
Which of these is NOT a wrapper class in Java?
What does
Double.parseDouble("3.14") return?Explain how to convert between Strings and primitive types using common wrapper methods in Java.
Describe the difference between primitive types and wrapper classes and why wrapper classes are useful.
