How to check if a specific character exists in a string with Java

1 Answer

0 votes
public class MyClass {
    public static void main(String args[]) {
        String s = "java"; 
      
        if (s.indexOf('j') != -1) 
            System.out.println("yes");
        else
            System.out.println("no");
    }
}



/*
run:
  
yes
  
*/

 



answered Jan 10, 2020 by avibootz

Related questions

1 answer 200 views
2 answers 133 views
1 answer 155 views
1 answer 175 views
1 answer 204 views
1 answer 227 views
2 answers 228 views
...