Wie kann ich ein Wort in einem String suchen

ich würd eher contains nehmen....

Java:
if("Ich will Bier".contains("Bier")){
         System.out.println("brav...");
      }


wobei es im grunde wenig unterschied macht...

/**
* Returns true if and only if this string contains the specified
* sequence of char values.
*
* @param s the sequence to search for
* @return true if this string contains <code>s</code>, false otherwise
* @throws NullPointerException if <code>s</code> is <code>null</code>
* @since 1.5
*/
public boolean contains(CharSequence s) {
return indexOf(s.toString()) > -1;
}
 

Zurück
Oben