StringBuffer append(String str) | This appends str to the current
string buffer. Alternative forms support appending primitives and character
arrays; these are converted to strings before appending. |
StringBuffer append(Object obj) | This calls toString() on obj
and appends the result to the current string buffer. |
StringBuffer insert(int offset, String str) | This inserts str
into the current string buffer at position offset. There are numerous alternative
forms. |
StringBuffer reverse() | This reverses the characters of the
current string buffer. |
StringBuffer setCharAt(int offset, char newchar) | This
replaces the character at position offset with newchar. |
StringBuffer setLengthInit newLength) | This sets the length
of the string buffer to newLength. If newLength is less than the current
length, the string is truncated. If newLength is greater than the current
length, the string is padded with null characters. |
| |
Method | Brief Description | Example |
1 | reverse, store, truncate, insert |
input: carpet
step one: teprac
step two: store last half of word (rac)
step three: truncate last half of word
step four: insert stored part (rac) infront of first part (tep)
result: ractep |
2 | pick random letter and alternately insert in front of it and
concat after it |
input: carpet
step one: pick random letter: (a) store it and delete it from input
step two: insert first letter from input infront of stored letter: ca
step three: concatenate next letter at end: car
repeat insert/concatenate: pcar, pcare, tpcare.
result: tpcare (actual results will vary since first letter is selected at
random). |
3 | store, truncate, random insert four times |
input: carpet
step one: store last letter (t), truncate last letter, randomly insert
possible result to step one: catrpe
step two: store last letter (e), truncate last letter, randomly insert
possible result to step two: caetrp
step three: store last letter (p), truncate last letter, randomly insert
possible result to step three: caetpr
step four: store last letter (r), truncate last letter, randomly insert
possible result to step four: caretp
result: caretp (actual results will vary since the four insertions are made
into randomly selected positions) |