Home > Back-end >  Java
Java

Time:09-24

Find online for help: array element, according to the value of input, output the corresponding position of the element, if the value is beyond the scope of the array number, silently,

CodePudding user response:

 public int searchArrayItem (int [] nums, int key) {
for (int i=0; i If (nums==[I] key)
return i;
}
return -1;
}
/* 8 stream Java
Int len=nums. Length;
Return IntStream. Range (0, len)
The filter (I - & gt; Key==nums [I])
FindFirst ()
. OrElse (1); */

CodePudding user response:

The Arrays. BinarySearch

JDK implementation of array element search, and returns the subscript, there is no return to plural, support for multiple array data type

CodePudding user response:

refer to the second floor dkwuxiang response:
Arrays. The binarySearch

JDK implementation of array element search, and returns the subscript, there is no return to plural, support a variety of data types array
is to sort an array of binary search method

CodePudding user response:

Yes, with binarySearch is binary search to find, first order