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

Answer:

Yes.


Size Limit

Another form of the split() method takes two parameters:

public String[] split(String RE, int limit)

This splits the original string into pieces, as before, but now the array it creates has no more than limit number of cells. The RE is matched at most limit-1 times, and then, a reference to whatever is left over is put in the last cell of the array. This fragment

String manyPets = "Ant, Bat, Cat, Dog" ;

String[] pieces = manyPets.split( ", *" , 3 );

creates an array of three cells

String[] pieces =   { "Ant", "Bat", "Cat, Dog"};

Details:

  1. If limit is positive, the array can have 1 up to limit number of cells.
  2. If limit is zero, the array can have any number of cells, but trailing empty strings are discarded.
  3. If limit is negative, the array can have any number of cells.

QUESTION 19:

What array is created by the following fragment:

String manyPets = "Ant, Bat, Cat, Dog, ,,,," ;

String[] pieces = manyPets.split( ", *" , 3 );