How to check if a string starts and ends with specific character in Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String str = "#java#";
    
        if (str.charAt(0) == '#' && str.charAt(str.length() - 1) == '#') 
            System.out.println("yes");
        else
            System.out.println("no");
    }
}


/*
run:

yes

*/

 



answered Apr 18, 2019 by avibootz

Related questions

...