Junior — Middle
What standard wrapper classes do you use for working with primitive types or collections?
sobes.tech AI
Answer from AI
In Java, wrapper classes from the java.lang package are used for working with primitive types:
IntegerforintLongforlongDoublefordoubleFloatforfloatBooleanforbooleanCharacterforcharByteforbyteShortforshort
These classes allow primitives to be used as objects, for example, in collections that only work with objects.
For working with collections, standard interfaces and classes from the java.util package are used, such as:
List(and implementations likeArrayList,LinkedList)Set(e.g.,HashSet,TreeSet)Map(e.g.,HashMap,TreeMap)
Example of using a wrapper class and a collection:
List<Integer> numbers = new ArrayList<>();
numbers.add(10); // Autoboxing int to Integer
int first = numbers.get(0); // Unboxing Integer to int