Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数组,integers里面有一些。我想检查一个给定integer的是否在其中。除了使用for循环来一一检查之外,还有没有indexOf在java中使用方法的方法?[ -1 如果不在其中,否则为索引]
integers
integer
for
indexOf
Java中的数组没有indexOf方法。您的主要选择是:
Arrays.binarySearch(array, number)
HashSet<Integer>
contains