code: public String next() {
          if (done) return null;
  
          // construct return value
  
          buffer.setLength(0); // delete old contents
          for (int i = 0; i < pieces.length; ++i) {
              buffer.append(pieces[i][current[i]]);
          }
          String result = buffer.toString();
  
          // find next value for next time
  
          for (int i = current.length - 1; ; --i) {
              if (i < 0) {
                  done = true;
                  break;
              }
              current[i]++;
              if (current[i] < pieces[i].length) break; // got sequence
              current[i] = 0;
          }
          return result;
      }
docs: Get the next canonically equivalent string.
  <br><b>Warning: The strings are not guaranteed to be in any particular order.</b>
  @return the next string that is canonically equivalent. The value null is returned when
  the iteration is done.