go to previous page   go to home page   go to next page

Answer:

The filled blanks are below.


Testing Strings for Equality

The if statement skips over cells that contain null. Otherwise, the method tests if cell 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 equivalent.


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 cell

  }
}

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

QUESTION 7:

Which of the following is true when array[j] and target refer to equivalent Strings?


go to previous page   go to home page   go to next page