How to get the first character of a string in Java

2 Answers

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

        System.out.println(s.substring(0, 1));

    }
}




/*
run:

j

*/

 



answered Feb 4, 2021 by avibootz
0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java programming";

        System.out.println(s.charAt(0));

    }
}




/*
run:

j

*/

 



answered Feb 4, 2021 by avibootz

Related questions

...