Java - Write code to last character in a string

Requirements

Write code to last character in a string

Demo

//package com.book2s;

public class Main {
    public static void main(String[] argv) {
        String s = "book2s.com";
        System.out.println(last(s));
    }/*from w  w w .  ja v  a 2s.c  om*/

    public static String last(String s) {
        if (s.isEmpty())
            throw new IllegalArgumentException(
                    "cannot get `last` of empty string");
        return s.substring(s.length() - 1);
    }
}