Junior — Middle
Mida tuleb märkida meetodis get(), kui saadakse üksik element List-tüüpi nimekirjast, kui nimekirja pikkus on 1
sobes.tech AI
Vastus AI-lt
If you have a List type list with length 1 and need to get the single element, you should pass index 0 to the get() method, because indexing in Java lists starts from zero.
Example:
List<String> list = new ArrayList<>();
list.add("element");
String singleElement = list.get(0); // Gets the first and only element
If you call get(1) or another index different from 0, when the list length is 1, an IndexOutOfBoundsException will be thrown.