To check if string contains particular word

后端 未结 10 701
野的像风
野的像风 2020-12-08 04:55

So how do you check if a string has a particular word in it?

So this is my code:

a.setOnClickListener(new View.OnClickListener() {

        @Overri         


        
10条回答
  •  無奈伤痛
    2020-12-08 05:19

    Using contains

    String sentence = "Check this answer and you can find the keyword with this code";
    String search = "keyword";
    
    if (sentence.toLowerCase().contains(search.toLowerCase())) {
    
      System.out.println("I found the keyword..!");
    
    } else {
    
      System.out.println("not found..!");
    
    }
    

提交回复
热议问题