How to check if a 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
...