question: public java . lang . String replace ( char oldChar , char newChar ) { char [ ] buffer = value ; int _offset = offset ; int _count = count ; int idx = _offset ; int last = _offset + _count ; boolean copied = false ; while ( idx < last ) { if ( buffer [ idx ] == oldChar ) { if ( ! copied ) { char [ ] newBuffer = new char [ _count ] ; System . arraycopy ( buffer , _offset , newBuffer , 0 , _count ) ; buffer = newBuffer ; idx -= _offset ; last -= _offset ; copied = true ; } buffer [ idx ] = newChar ; } idx ++ ; } return copied ? new String ( buffer ) : this ; }
target:  Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. If the character oldChar does not occur in the character sequence represented by this String object, then a reference to this String object is returned. Otherwise, a new String object is created that represents a character sequence identical to the character sequence represented by this String object, except that every occurrence of oldChar is replaced by an occurrence of newChar. Examples: "mesquite in your cellar".replace('e', 'o') returns "mosquito in your collar" "the war of baronets".replace('r', 'y') returns "the way of bayonets" "sparring with a purple porpoise".replace('p', 't') returns "starring with a turtle tortoise" "JonL".replace('q', 'x') returns "JonL" (no change)