I am trying to find the index of a string in a string array using the Arrays.binarySearch() method however the method seems to be return the postion integer "-5" when looking for the string "Free". Any idea why this would be?
String[] names = {"Arken","Ben","Darklark", "Free","group"};
void changeFriends(String uname, boolean b)
{ // change a friend's "online" status
Arrays.sort(names);
int index = Arrays.binarySearch(names, uname);
System.out.println("NAME OF ONLINE USER IS AT INDEX:" + index + "Name:" + uname);
if(index > -1)
{
if(b == true)
{
loggedOn[index] = true;
}
else
{
loggedOn[index] = false;
}
}
// call method to update buttons
changeNameButtons();
}
NAME OF ONLINE USER IS AT INDEX: 3 Name:Free