How to get a substring from the last character of a String in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        try {
 
            String s = "java c c++";
 
            String part = s.substring(s.length() - 3);
 
            System.out.println(part);
 
        } catch (Exception e) {
            System.out.print(e.toString());
        }
    }
}



/*

c++
     
*/

 



answered Nov 26, 2016 by avibootz
edited Oct 6, 2023 by avibootz
...