How to get the last character of a string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java c c++ python";
        
        char last_ch = s.charAt(s.length() - 1);
        System.out.println(last_ch);
    }
}



/*
run:

n

*/

 



answered Mar 17, 2021 by avibootz
...