Home  >  Article  >  Java  >  How to determine whether a specified character exists in java

How to determine whether a specified character exists in java

尚
Original
2019-12-28 15:10:023264browse

How to determine whether a specified character exists in java

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 the java Basic Tutorial column .

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn