Retornar o último elemento

Retorne o último elemento de um array ou o último caractere de uma string. Se a entrada estiver vazia, retorne null.

Exemplos

Program.lastItem(new Integer[]{0, 4, 19, 34, 50, -9, 2}) ➞ 2

Program.lastItem("The quick brown fox jumped over the lazy dog") ➞ 'g'

Program.lastItem(new Integer[0]) ➞ null

Notas

  • Os arrays e as strings podem ter tamanhos diferentes.
  • Retorne null se a entrada estiver vazia.