get last letter of string code example

Example 1: java get last char of string

public class Test {
    public static void main(String args[]) {
        String string = args[0];
        System.out.println("last character: " +
                           string.substring(string.length() - 1)); 
    }
}

Example 2: javascript get last n characters of string

'abc'.slice(-1); // c

Example 3: how to get last string in javascript

'abc'.slice(-2);

Example 4: last char in string java

public class Test {
    public static void main(String args[]) {
        String string = args[0];
        System.out.println("last character: " +
                           string.substring(string.length() - 1)); 
    }
}

Tags:

Java Example