Sobes.tech
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:

  • Integer for int
  • Long for long
  • Double for double
  • Float for float
  • Boolean for boolean
  • Character for char
  • Byte for byte
  • Short for short

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 like ArrayList, 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
What standard wrapper classes do you use for working… - sobes.tech