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