Home > Mobile >  The Arrays. BinarySearch cannot find the string?
The Arrays. BinarySearch cannot find the string?

Time:09-17


 public class BinarySearchTest {

Public static String [] deviceIds={
"44: EF: BF: f: 84:0 e",
"38:01: be F: F7:18",
"CC: 79: CF: A7:8 b: 15",
"6 c: 21: A2: E1: E6:5 d",
"6 c: 21: A2: E1: E6:82",
"6 c: 21: A2: E1: D9: C9",
"6 c: 21: A2: E1, E0:11"};
Public static void main (String [] args) {

For (String deviceId: deviceIds) {
System. The out. Println (" binarySearch: "+ Arrays. BinarySearch (deviceIds, deviceId));
}
}

}




Output:
Task: JavaTest: BinarySearchTest. The main ()
3
binarySearch: -BinarySearch: 1
8
binarySearch: -BinarySearch: 3
8
binarySearch: -3
binarySearch: -3
binarySearch: -



CodePudding user response:

Arrays. BinarySearch () use is the premise of array is ordered,
  • Related