How to get the last two letters of a string in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java";
        
        System.out.println(s.substring(s.length() - 2));
    }
}



/*
run:

va

*/

 



answered Nov 1, 2020 by avibootz

Related questions

...