code: public T[] nextPermutationAsArray(T[] destination)
      {
          if (destination.length != elements.length)
          {
              throw new IllegalArgumentException("Destination array must be the same length as permutations.");
          }
          generateNextPermutationIndices();
          // Generate actual permutation.
          for (int i = 0; i < permutationIndices.length; i++)
          {
              destination[i] = elements[permutationIndices[i]];
          }
          return destination;
      }
docs: Generate the next permutation and return an array containing
  the elements in the appropriate order.  This overloaded method
  allows the caller to provide an array that will be used and returned.
  The purpose of this is to improve performance when iterating over
  permutations.  If the {@link #nextPermutationAsArray()} method is
  used it will create a new array every time.  When iterating over
  permutations this will result in lots of short-lived objects that
  have to be garbage collected.  This method allows a single array
  instance to be reused in such circumstances.
  @param destination Provides an array to use to create the
  permutation.  The specified array must be the same length as a
  permutation.  This is the array that will be returned, once
  it has been filled with the elements in the appropriate order.
  @return The next permutation as an array.