博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Java String.contains()方法
阅读量:6895 次
发布时间:2019-06-27

本文共 879 字,大约阅读时间需要 2 分钟。

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.

实例

下面的例子说明了如何使用java.lang.String.contains()方法

package com.yiibai;import java.lang.*;public class StringDemo {  public static void main(String[] args) {      String str1 = "tutorials point", str2 = "http://";    CharSequence cs1 = "int";        // string contains the specified sequence of char values    boolean retval = str1.contains(cs1);    System.out.println("Method returns : " + retval);        // string does not contain the specified sequence of char value    retval = str2.contains("_");       System.out.println("Methods returns: " + retval);  }}

让我们来编译和运行上面的程序,这将产生以下结果:

Method returns : trueMethods returns: false

转载地址:http://gvkdl.baihongyu.com/

你可能感兴趣的文章
zt:Linux查看程序端口占用情况
查看>>
iis下thinkphp配置url rewrite伪静态
查看>>
jQuery-表单选择器
查看>>
Unique Binary Search Trees-计算表示相同序列的不同BST个数
查看>>
git 第三天 SSH免密码登录 1
查看>>
Notepad++ 列操作
查看>>
window.XMLHttpRequest
查看>>
【原】iOS学习之ARC和非ARC文件混编
查看>>
方法过滤器,分布式缓存 Memcached实现Session解决方案
查看>>
装在u盘的linux
查看>>
ASP.NET几种页面数据绑定的用法及区别: <%#、 <%=、 <% 、<%@
查看>>
zookeeper
查看>>
java scoket (UDP通信模型)简易聊天室
查看>>
第六周作业
查看>>
Failed to allocate the network(s), not rescheduling
查看>>
指针字符串
查看>>
Wpf 自定义控件(1)
查看>>
【Marva Collins' Way】第一章
查看>>
iOS(OC)中的冒泡排序
查看>>
Intellij IDEA 与 Gitlab 实现代码上传与下载
查看>>