Core Java API Flashcards
7 cards from real 1Z0-811 practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Core Java API flashcards as text
What does `String.valueOf(null)` return when the argument is a `char[]` variable set to null?
Answer: NullPointerException
Calling `String.valueOf((char[]) null)` throws a NullPointerException because the char[] overload dereferences the array.
Which method of `StringBuilder` reverses the character sequence in place?
Answer: reverse()
`StringBuilder.reverse()` reverses the sequence of characters and returns the same StringBuilder.
Given `List list = List.of("a","b","c");`, what happens when you call `list.set(0, "z")`?
Answer: Throws UnsupportedOperationException
Lists created with `List.of()` are immutable, so any structural or element-change operation throws UnsupportedOperationException.
What is the output of `System.out.println(Math.floor(-2.5))`?
Answer: -3.0
`Math.floor()` returns the largest double less than or equal to the argument, so -2.5 floors to -3.0.
Which interface does `HashMap` directly implement?
Answer: Map
`HashMap` directly implements the `Map` interface and extends `AbstractMap`.
What is the result of `"hello".substring(2, 4)`?
Answer: "ll"
`substring(beginIndex, endIndex)` returns characters from index 2 (inclusive) to 4 (exclusive): 'l' and 'l'.
Which `Optional` method returns the value if present, otherwise throws `NoSuchElementException`?
Answer: get()
`Optional.get()` returns the value if present, but throws `NoSuchElementException` if the Optional is empty.