问题:
我正在使用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
时,但是当我输入_
时然后跟随 o
或s
它向我显示了其他类似 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/