Java中的String.contains [英] String.contains in Java

查看:137
本文介绍了Java中的String.contains的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String s1 = "The quick brown fox jumps over the lazy dog";
String s2 = "";
boolean b = s1.contains(s2);
System.out.println(b);

我运行上面的Java代码,b返回t​​rue。
由于s2为空,为什么s1包含s2?

I run the Java code above, the b return true. Since s2 is empty, why does s1 contains s2?

我检查Java API,它写道:

I check the Java API, it write:

当且仅当此字符串包含指定的char值序列时,才返回true。

Returns true if and only if this string contains the specified sequence of char values.

参数:

s - 要搜索的序列

s - the sequence to search for

返回:

如果此字符串包含s,则返回true,否则返回false

true if this string contains s, false otherwise

推荐答案

Empty是任何字符串的子集。

Empty is a subset of any string.

将它们视为每两个字符之间的差异。

Think of them as what is between every two characters.

存在无限数字的方式在任何大小的线上的点......

Kind of the way there are an infinite number of points on any sized line...

(嗯......我想知道如果我使用微积分来连接无数个空字符串我会得到什么)

(Hmm... I wonder what I would get if I used calculus to concatenate an infinite number of empty strings)

请注意.equals()仅限。

Note that "".equals("") only though.

这篇关于Java中的String.contains的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆