字符串java开始于

发布于 2024-12-23 21:37:24 字数 365 浏览 1 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(7

你不是我要的菜∠ 2024-12-30 21:37:25

字符串并不像您想象的那么相同。第一个字符串包含 forgotPwd,而第二个字符串包含 forgetPwd

The strings are not as identical as you think. The first string contains forgotPwd while the second contains forgetPwd.

寂寞笑我太脆弱 2024-12-30 21:37:25

因为在第一个字符串中您有 forgotPwd ,而在第二个字符串中您有 forgetPwd 。区别在于 oe

because in 1st string you are having forgotPwd and in second forgetPwd . Difference is o and e

梦里寻她 2024-12-30 21:37:25

您的 s1 不是 s2 的一部分。 forgotPwd

检查一下。

String s1 = "/program/rest/user/forgotPwd/";
String s2 = "/program/rest/user/forgotPwd/test";
System.out.println(s1.startsWith(s2));
System.out.println(s2.startsWith(s1));

输出:

false
true

Your s1 is not a part of s2. forgotPwd

Check this.

String s1 = "/program/rest/user/forgotPwd/";
String s2 = "/program/rest/user/forgotPwd/test";
System.out.println(s1.startsWith(s2));
System.out.println(s2.startsWith(s1));

Output:

false
true
安穩 2024-12-30 21:37:25

情况 1 是显而易见的。
情况 2 为假,因为 s1 具有“忘记”而 s2 具有“忘记”。

case 1 is obvious.
case 2 is false because s1 has "forgot" and s2 has "forget".

亣腦蒛氧 2024-12-30 21:37:25

那是自然的。仔细看看你的琴弦。

String s1 = "/program/rest/user/forgotPwd/";
String s2 = "/program/rest/user/forgetPwd/test";

s1 有单词 forgotPwd,s2 有 forgetPwd。相差1个字母。

That's natural. Look closer at your strings.

String s1 = "/program/rest/user/forgotPwd/";
String s2 = "/program/rest/user/forgetPwd/test";

s1 has the word forgotPwd, s2 has forgetPwd. There is 1 letter difference.

紙鸢 2024-12-30 21:37:25

你在s2中有一个拼写错误,它说:

字符串 s2 = "/program/rest/user/forgetPwd/test";

它应该说:

字符串 s2 = "/program/rest/user/forgotPwd/test";

You have a typo in s2 it says:

String s2 = "/program/rest/user/forgetPwd/test";

and it should say:

String s2 = "/program/rest/user/forgotPwd/test";

浅唱ヾ落雨殇 2024-12-30 21:37:25

的形式的索引

        "Foobar".startsWith("bar", 3) 

也许您可以尝试指定返回 true 。当然是在检查完你的拼写错误之后。

Maybe you could try specifying an index of the form

        "Foobar".startsWith("bar", 3) 

which returns true. After checking your typos of course.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文