Okay here is the code

public void Search()
      System.out.println("Who do you want to find? ");
      System.out.println("Last Name: ");

      String Value;
      doubleNode Temp;
      Temp = list.getBegin();

      int k = 0;
      String [] lis = {"","","","","","","","","","","","","","","","","","","",""};
      String [] result = {"","","","","","","","","","","","","","","","","","","",""};

      while( (Value = Temp.getValue()) != null)
         lis [k] = Value;
         String [] tokens = lis [k].split(" ");
         result [k] = tokens[3];
         Temp = Temp.getNext();
         if(Temp == null)

      String Name = Input.next();
      int index = Arrays.binarySearch(result, Name);

      if (index >= 0 )  
         System.out.println(Name + " is in the Roster");  
         System.out.println(Name + " is not in the Roster.");  


It seems that the problem has something to do with the binary search, but I don't know what it is. The idex result is always -21.

Can you post the output from the program. Have you read the API doc for the binareySearch method to see what values it returns? Why do you think -21 is wrong?
When does the array; result get any non empty values? Have you printed out the contents of result to see what it is loaded with? How many elements does it have? Change the number of elements and see if the value of index changes.

Edited 4 Years Ago by NormR1

This article has been dead for over six months. Start a new discussion instead.