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  www.j  a  va 2  s . c  o m

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