gpt4 book ai didi

java - Collections.binarySearch (Java) 中下划线(_) 的问题

转载 作者:行者123 更新时间:2023-12-02 00:51:48 26 4
gpt4 key购买 nike

问题:

我正在使用Java Tutorials™这个的源代码。这是source code.

我试过这个:

--following with another section of sorted words--
words.add("count");
words.add("cvs");
words.add("dce");
words.add("depth");
--following with another section of sorted words--

而且它工作得很好。但是当我使用这个时:

--just a section of sorted words--
words.add("count");
words.add("cvs");
words.add("dce_iface");
words.add("dce_opnum");
words.add("dce_stub_data");
words.add("depth");
--following with another section of sorted words--

它确实显示 dce_iface当我输入dce时,但是当我输入_时然后跟随 os它向我显示了其他类似 dce_offset 的内容偏移量来自 words.add("fragoffset");列表中的某个位置。

我可以做什么来解决这个问题?预先感谢您。

最佳答案

这可能是因为代码中的这些行:

for (w = pos; w >= 0; w--) {
if (! Character.isLetter(content.charAt(w))) {
break;
}
}

_ 不是字母字符,因此它将其视为空格。您可以尝试将条件更改为:

char c = content.charAt(w);
if (! (Character.isLetter(c) || c == '_')) {

关于java - Collections.binarySearch (Java) 中下划线(_) 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2714353/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com