A good answer might be:

The filled blanks are below.

Testing Strings for Equality

class Searcher
{
  // seek target in the array of strings.
  // return the index where found, or -1 if not found.
  public static int search( String[] array, String target )
  {
     for ( int j=0; j  < array.length; j++ )
       if ( array[j] != null )
         // do something here with a non-null slot

  }
}

class SearchTester
{
  public static void main ( String[] args )
  {
    . . . . . .
    int where = Searcher.search( strArray, "Peoria" );
    . . . . . .
  }
}

The if statement allows only non-null slots to be used with the statement that will replace "// do something here."

The "// do something here" statment will test if slot j of the array refers to a string that matches target. In other words, we want to test if the contents of two strings are equal.


QUESTION 14:

Which of the following evaluates to true when the array[ j ] refers to a string that is the equivalent of the one target refers to?

  • array[ j ] = target
  • array[ j ] == target
  • array[ j ].equals( target )
Click Here after you have answered the question