这篇文章给大家分享的是java判断字符是否存在的方法。小编觉得挺实用的,因此分享给大家做个参考。一起跟随小编过来看看吧。

java中可以使用contains方法判断指定字符是否存在。

java.lang.String.contains()方法返回true,当且仅当此字符串包含指定的char值序列

声明

以下是声明java.lang.String.contains()方法

public boolean contains(CharSequence s)

参数:s-- This is the sequence to search for.

返回值:如果此字符串包含,此方法返回true,否则返回false。

异常:NullPointerException-- if s is null.

示例:

public static void main(String[] args) {    String str = "abc"; boolean status = str.contains("a"); if(status){ System.out.println("包含"); }else{ System.out.println("不包含"); }}

看完这篇文章,你们学会使用contains方法判断指定字符是否存在的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注亿速云行业资讯频道,感谢各位的阅读。