I created two arrays one of integers and another of Strings (objects), but when I used the binarySearch method to know the position of the elements, the return of the positions of the Strings array went differently, why did this happen?
showing code and return.
import java.util.Arrays;
public class ArraySimples {
public static void main(String[] args) {
String [] paises ={"Brasil", "Russia", "India", "China", "Argentina","Paraguai"};
int [] numeros = {5,7,9,11,13};
int posicao0 =Arrays.binarySearch(paises, "Brasil");
int posicao1 =Arrays.binarySearch(paises, "Russia");
int posicao2 =Arrays.binarySearch(paises, "India");
int posicao3 =Arrays.binarySearch(paises, " China");
int posicao4 =Arrays.binarySearch(paises, "Argentina");
int posicao5 =Arrays.binarySearch(paises, "Paraguai");
System.out.println("Brasil: " + posicao0);
System.out.println("Russia: " + posicao1);
System.out.println("India: " + posicao2);
System.out.println("China: " + posicao3);
System.out.println("Argentina:" + posicao4);
System.out.println("Paraguai" + posicao5);
int posicao00 =Arrays.binarySearch(numeros, 5);
int posicao11 =Arrays.binarySearch(numeros, 7);
int posicao22 =Arrays.binarySearch(numeros, 9);
int posicao33 =Arrays.binarySearch(numeros, 11);
int posicao44 =Arrays.binarySearch(numeros, 13);
System.out.println("5: " + posicao00);
System.out.println("7: " + posicao11);
System.out.println("9: " + posicao22);
System.out.println("11: " + posicao33);
System.out.println("13: " +posicao44);
}
}