public String convert(String string, Locale locale) {

    if ((string == null) || (string.isEmpty())) {
      return string;
    }
    // fast and simple cases first...
    if ((!hasWordSeparator()) && (this.wordStartCase == this.otherCase)) {
      String s = string;
      if (this.wordSeparator == null) {
        s = removeSpecialCharacters(s);
      }
      if (this.firstCase == this.wordStartCase) {
        s = this.firstCase.convert(s, locale);
      } else {
        String first = this.firstCase.convert(s.substring(0, 1), locale);
        String rest = this.otherCase.convert(s.substring(1), locale);
        s = first + rest;
      }
      return s;
    }
    CharIterator charIterator = new SequenceCharIterator(string);
    StringBuilder buffer = new StringBuilder(string.length() + 4);
    char c = charIterator.next();
    CharClass previousClass = CharClass.of(c);
    while (previousClass.isSeparatorOrDollar()) {
      if ((buffer.length() == 0) && hasWordSeparator()) {
        buffer.append(this.wordSeparator);
      }
      if (!charIterator.hasNext()) {
        return buffer.toString();
      }
      c = charIterator.next();
      previousClass = CharClass.of(c);
    }
    appendCasedChar(buffer, c, this.firstCase);
    CaseConversion previousCase = CaseConversion.ofExample(c, false);
    int start = 1;
    int end = start;
    while (charIterator.hasNext()) {
      c = charIterator.next();
      CharClass currentClass = CharClass.of(c);
      CaseConversion currentCase = CaseConversion.ofExample(c, false);
      switch (currentClass) {
        case LETTER:
          if (previousClass.isSeparatorOrDollar()) {
            appendCasedChar(buffer, c, this.wordStartCase);
            start++;
          } else if (currentCase != previousCase) {
            if ((currentCase == CaseConversion.UPPER_CASE) && (end > 1)) {
              assert (previousCase == CaseConversion.LOWER_CASE);
              start = appendOthers(string, buffer, start, end);
              if (hasWordSeparator()) {
                buffer.append(this.wordSeparator);
              }
              appendCasedChar(buffer, c, this.wordStartCase);
            }
          }
          break;
        case SEPARATOR:
        case DOLLAR:
          if (!previousClass.isSeparatorOrDollar()) {
            start = appendOthers(string, buffer, start, end);
            if (KEEP_SPECIAL_CHARS.equals(this.wordSeparator)) {
              buffer.append(c);
            } else if (this.wordSeparator != null) {
              buffer.append(this.wordSeparator);
            }
          } else {
            start++;
          }
          break;
        default :
          break;
      }
      if (currentClass != CharClass.DIGIT) {
        previousClass = currentClass;
        previousCase = currentCase;
      }
      end++;
    }
    if (start < end) {
      appendOthers(string, buffer, start, end);
    }
    return buffer.toString();
  }
public String convert ( String string , Locale locale ) { if ( ( string == null ) || ( string . isEmpty ( ) ) ) { return string ; } if ( ( ! hasWordSeparator ( ) ) && ( this . wordStartCase == this . otherCase ) ) { String s = string ; if ( this . wordSeparator == null ) { s = removeSpecialCharacters ( s ) ; } if ( this . firstCase == this . wordStartCase ) { s = this . firstCase . convert ( s , locale ) ; } else { String first = this . firstCase . convert ( s . substring ( 0 , 1 ) , locale ) ; String rest = this . otherCase . convert ( s . substring ( 1 ) , locale ) ; s = first + rest ; } return s ; } CharIterator charIterator = new SequenceCharIterator ( string ) ; StringBuilder buffer = new StringBuilder ( string . length ( ) + 4 ) ; char c = charIterator . next ( ) ; CharClass previousClass = CharClass . of ( c ) ; while ( previousClass . isSeparatorOrDollar ( ) ) { if ( ( buffer . length ( ) == 0 ) && hasWordSeparator ( ) ) { buffer . append ( this . wordSeparator ) ; } if ( ! charIterator . hasNext ( ) ) { return buffer . toString ( ) ; } c = charIterator . next ( ) ; previousClass = CharClass . of ( c ) ; } appendCasedChar ( buffer , c , this . firstCase ) ; CaseConversion previousCase = CaseConversion . ofExample ( c , false ) ; int start = 1 ; int end = start ; while ( charIterator . hasNext ( ) ) { c = charIterator . next ( ) ; CharClass currentClass = CharClass . of ( c ) ; CaseConversion currentCase = CaseConversion . ofExample ( c , false ) ; switch ( currentClass ) { case LETTER : if ( previousClass . isSeparatorOrDollar ( ) ) { appendCasedChar ( buffer , c , this . wordStartCase ) ; start ++ ; } else if ( currentCase != previousCase ) { if ( ( currentCase == CaseConversion . UPPER_CASE ) && ( end > 1 ) ) { assert ( previousCase == CaseConversion . LOWER_CASE ) ; start = appendOthers ( string , buffer , start , end ) ; if ( hasWordSeparator ( ) ) { buffer . append ( this . wordSeparator ) ; } appendCasedChar ( buffer , c , this . wordStartCase ) ; } } break ; case SEPARATOR : case DOLLAR : if ( ! previousClass . isSeparatorOrDollar ( ) ) { start = appendOthers ( string , buffer , start , end ) ; if ( KEEP_SPECIAL_CHARS . equals ( this . wordSeparator ) ) { buffer . append ( c ) ; } else if ( this . wordSeparator != null ) { buffer . append ( this . wordSeparator ) ; } } else { start ++ ; } break ; default : break ; } if ( currentClass != CharClass . DIGIT ) { previousClass = currentClass ; previousCase = currentCase ; } end ++ ; } if ( start < end ) { appendOthers ( string , buffer , start , end ) ; } return buffer . toString ( ) ; }
Converts to this {@link CaseSyntax}. The first character will be converted using {@link #getFirstCase()}.
Characters other than {@link Character#isLetterOrDigit(char) letters or digits} are considered as word separator.
In the most cases, they will be

@param string the {@link String} to convert.
@param locale the explicit {@link Locale} to use. In most cases you want to use {@link #convert(String)} instead.
@return the String converted to this {@link CaseSyntax}.