Skip to main content

APIzation: Replication Package

[Q#5163785][A#5163852] How do I get the last character of a string?

https://stackoverflow.com/q/5163785

How do I get the last character of a string?

Answer

https://stackoverflow.com/a/5163852

The code: The output:

APIzation

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

public class Human5163852 {

  public static String getLastChar(String str1) {
    String string = str1;
    return string.substring(string.length() - 1);
  }
}

package com.stackoverflow.api;

/**
 * How do I get the last character of a string?
 *
 * @author APIzator
 * @see <a href="https://stackoverflow.com/a/5163852">https://stackoverflow.com/a/5163852</a>
 */
public class APIzator5163852 {

  public static String getCharacter(String str1) {
    String string = str1;
    return string.substring(string.length() - 1);
  }
}