Explain the Collector framework in Java Streams.
The Collector Framework in Java's Stream API provides a set of utilities to
aggregate, transform, and collect the results of stream operations into a desired
format,
such as a List, Set, Map, or even a single value. Collectors are part of the
[Link] package and are typically used with the [Link]() terminal
operatio
Explain bounded and unbounded wildcards in Java?
Unbounded Wildcard (?)
Definition: Represents any type.
Usage: When you don’t care about the specific type and just need to work with a
collection of any type.
Example: List<?> list = new ArrayList<>();
Limitations: You can’t add elements (except null). You can only read as Object.
Upper-Bounded Wildcard (? extends T)
Definition: Represents any type that is T or a subtype of T.
Usage: When you want to read from a collection and are interested in subtypes of T
(e.g., List<? extends Number> can be List<Integer> or List<Double>).
Example: List<? extends Number> list = new ArrayList<Integer>();
Limitations: You cannot add elements because the specific subtype is unknown.
Lower-Bounded Wildcard (? super T)
Definition: Represents any type that is T or a supertype of T.
Usage: When you want to add elements of type T to a collection (e.g., List<? super
Integer> can accept Integer, Number, or Object).
Example: List<? super Integer> list = new ArrayList<Number>();
Limitations: You can’t safely read elements, as they are of type Object or a
supertype of T.
Summary:
?: Can be any type (read-only, no adding).
? extends T: Subtype of T (read-only).
? super T: Supertype of T (write-only, can add T).