In Java, you can use the contains method to determine whether the specified character exists.
The java.lang.String.contains() method returns true if and only if this string contains the specified char value sequence
Statement
The following is the statement java. lang.String.contains() method
public boolean contains(CharSequence s)
Parameters: s-- This is the sequence to search for.
Return value: if This string contains, this method returns true, otherwise it returns false.
Exception: NullPointerException-- if s is null.
Example:
public static void main(String[] args) { String str = "abc"; boolean status = str.contains("a"); if(status){ System.out.println("包含"); }else{ System.out.println("不包含"); } }
For more java knowledge, please pay attention to thejava Basic Tutorialcolumn .
The above is the detailed content of How to determine whether a specified character exists in java. For more information, please follow other related articles on the PHP Chinese website!