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.
我有字符串数组 [1, 2, 3],我使用 Arrays.binarySearch 搜索所有这些数字,它找到 1 和 2,但使用 3 它返回 -1。知道为什么它会这样工作吗?在数组/集合中始终工作搜索有什么更好的选择?
必须对数组进行排序。
String []ar={"1","2","3"}; System.out.println(java.util.Arrays.binarySearch(ar,"3"));