哪里是Java数组的indexOf? [英] Where is Java's Array indexOf?

查看:676
本文介绍了哪里是Java数组的indexOf?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须失去了一些东西很明显,但我已经找遍了,不能找到这个方法。

I must be missing something very obvious, but I've searched all over and can't find this method.

推荐答案

有几个方法可以做到这一点使用<$c$c>Arrays实用工具类。

There are a couple of ways to accomplish this using the Arrays utility class.

如果阵列没有排序:

java.util.Arrays.asList(theArray).indexOf(o)

如果数组排序,你可以利用性能二进制搜索的:

If the array is sorted, you can make use of a binary search for performance:

java.util.Arrays.binarySearch(theArray, o)

这篇关于哪里是Java数组的indexOf?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆