What OOP concept is demonstrated when a single method call behaves differently depending on the object's type?
Inheritance
Abstraction
Encapsulation
Polymorphism
Which method converts a stream of strings to a single comma-separated string?
collect(Collectors.joining(", "))
Both A and B
reduce(", ", String::concat)
map(String::concat).collect(Collectors.toList())
Which type of collection is inherently thread-safe and specifically designed for concurrent access in Java?
ConcurrentHashMap
ArrayList
TreeMap
HashSet
Which data structure is best suited for implementing a Last-In-First-Out (LIFO) order of elements in Java?
Set
Queue
Stack
Map
What will the following code snippet print?
List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); long count = numbers.stream().filter(n -> n % 2 == 0).map(n -> n * 2).count(); System.out.println(count);
5
2
4
10
What is a custom collector in Java Streams?
A mechanism for sorting stream elements in a custom order
A way to filter elements in a stream based on custom logic
A predefined collector provided by the Java API
A user-defined collector to perform specific aggregation operations
What will LocalDate.now().plusDays(1) return?
LocalDate.now().plusDays(1)
The current date and time.
The date one day after the current date.
The date one day before the current date.
An error, as the plusDays() method does not exist.
plusDays()
Which class in the java.time package represents a date without a time component?
java.time
LocalDateTime
ZonedDateTime
LocalDate
Instant
Which interface does Java primarily use to represent a task that can be executed concurrently?
Iterable
Runnable
Threadable
Callable
What is the time complexity of retrieving an element from a HashSet in Java, assuming the hash function distributes elements evenly?
O(n log n)
O(1)
O(n)
O(log n)