Arrays and ArrayList

Read the last title in each list. If the list has no titles, return "Empty".

Examples

Example 1

Input
["Maps", "Weather", "Stars"]
Expected output
Stars

Example 2

Input
[]
Expected output
Empty

Hints and solution

Hint 1

Check the size before trying to get the last entry.

Reveal worked answer

When the size is positive, the last valid index is size() - 1. Check isEmpty() before calling get.

Back to the lesson