Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
给定以下字符串
String a = "hello"; String b = "hell"; String c = "help";
我想知道字符串 b 是否是 a 的子字符串,以及字符串 c 是否是 a 的子字符串。
您可以在这里看到答案显然是 b 是肯定的,而 c 是否定的。如何在 Java 中执行此测试?
很简单:
if (a.startsWith(b))
尝试这个:
if(a.contains(b)) {...} if(a.contains(c)) {...}
也适用于:
if(a.contains("ell")) {...}