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

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java programming";

        String let = s.substring(0, 2);
        
        System.out.println(let);
    }
}



/*
run:

ja

*/

 



answered Oct 29, 2020 by avibootz
...