indzi
10/2/2017 - 7:17 AM

Getting last three characters of a string

Getting last three characters of a string

if (word.length() == 3) {
  return word;
} else if (word.length() > 3) {
  return word.substring(word.length() - 3);
} else {
  // whatever is appropriate in this case
  throw new IllegalArgumentException("word has less than 3 characters!");
}