字符串java开始于
public class Test {
public static void main(String[] args) throws Exception {
String s1 = "/program/rest/user/forgotPwd/";
String s2 = "/program/rest/user/forgetPwd/test";
System.out.println(s1.startsWith(s2));
System.out.println(s2.startsWith(s1));
}
}
两种情况都会打印 false
。有什么解释吗?
public class Test {
public static void main(String[] args) throws Exception {
String s1 = "/program/rest/user/forgotPwd/";
String s2 = "/program/rest/user/forgetPwd/test";
System.out.println(s1.startsWith(s2));
System.out.println(s2.startsWith(s1));
}
}
Both the cases print false
. Any explanations?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
字符串并不像您想象的那么相同。第一个字符串包含
forgotPwd
,而第二个字符串包含forgetPwd
。The strings are not as identical as you think. The first string contains
forgotPwd
while the second containsforgetPwd
.因为在第一个字符串中您有
forgotPwd
,而在第二个字符串中您有forgetPwd
。区别在于o
和e
because in 1st string you are having
forgotPwd
and in secondforgetPwd
. Difference iso
ande
您的 s1 不是 s2 的一部分。
forgotPwd
检查一下。
输出:
Your s1 is not a part of s2.
forgotPwd
Check this.
Output:
情况 1 是显而易见的。
情况 2 为假,因为 s1 具有“忘记”而 s2 具有“忘记”。
case 1 is obvious.
case 2 is false because s1 has "forgot" and s2 has "forget".
那是自然的。仔细看看你的琴弦。
s1 有单词
forgotPwd
,s2 有forgetPwd
。相差1个字母。That's natural. Look closer at your strings.
s1 has the word
forgotPwd
, s2 hasforgetPwd
. There is 1 letter difference.你在s2中有一个拼写错误,它说:
它应该说:
You have a typo in s2 it says:
and it should say:
的形式的索引
也许您可以尝试指定返回 true 。当然是在检查完你的拼写错误之后。
Maybe you could try specifying an index of the form
which returns true. After checking your typos of course.