How do I get the last character of a string?

前端 未结 11 2224
遥遥无期
遥遥无期 2020-12-02 07:59

How do I get the last character of a string?

public class Main {
    public static void main(String[] args)  {
        String s = "test string";
            


        
11条回答
  •  清歌不尽
    2020-12-02 08:31

     public char lastChar(String s) {
         if (s == "" || s == null)
            return ' ';
        char lc = s.charAt(s.length() - 1);
        return lc;
    }
    

提交回复
热议问题