I\'m trying to take the last three chracters of any string and save it as another String variable. I\'m having some tough time with my thought process.
Strin
I would consider right
method from StringUtils
class from Apache Commons Lang:
http://commons.apache.org/proper/commons-lang/apidocs/org/apache/commons/lang3/StringUtils.html#right(java.lang.String,%20int)
It is safe. You will not get NullPointerException
or StringIndexOutOfBoundsException
.
Example usage:
StringUtils.right("abcdef", 3)
You can find more examples under the above link.