字符串数组中的indexOf
无论如何,是否可以像在字符串中一样获取indexOf。
output.add("1 2 3 4 5 6 7 8 9 10);
String bigger[] = output.get(i).split(" ");
int biggerWher = bigger.indexOf("10");
我编写了这段代码,但它返回错误并且无法编译!有什么建议吗?
Is there anyway to get indexOf like you would get in a string.
output.add("1 2 3 4 5 6 7 8 9 10);
String bigger[] = output.get(i).split(" ");
int biggerWher = bigger.indexOf("10");
I wrote this code but its returning an error and not compiling! Any advice ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
使用这个...
Use this ...
当数组是对象数组时,则:
另一种选择是
org.apache.commons.lang.ArrayUtils.indexOf(...)
也具有原始类型数组的重载,以及采用起始偏移量的 3 参数版本。 (Apache 版本应该更高效,因为它们不需要创建临时List
实例。)When the array is an array of objects, then:
Another alternative is
org.apache.commons.lang.ArrayUtils.indexOf(...)
which also has overloads for arrays of primitive types, as well as a 3 argument version that takes a starting offset. (The Apache version should be more efficient because they don't entail creating a temporaryList
instance.)数组没有
indexOf()
方法;但是,java.util.List
可以。因此,您可以将数组包装在列表中并使用List
方法(add()
等除外):Arrays do not have an
indexOf()
method; however,java.util.List
does. So you can wrap your array in a list and use theList
methods (except foradd()
and the like):您可以使用 java.util.Arrays.binarySearch(array, item);
这将为您提供该项目的索引(如果有)...
但是请注意,在搜索之前需要对数组进行排序。
问候
You can use
java.util.Arrays.binarySearch(array, item);
That will give you an index of the item, if any...
Please note, however, that the array needs to be sorted before searching.
Regards
Java数组中没有直接的indexOf方法。
There is no direct indexOf method in Java arrays.
10点后你错过了
"
。you miss a
"
after 10.