StringBuilder.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707
  1. /* StringBuilder.java -- Unsynchronized growable strings
  2. Copyright (C) 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2008
  3. Free Software Foundation, Inc.
  4. This file is part of GNU Classpath.
  5. GNU Classpath is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2, or (at your option)
  8. any later version.
  9. GNU Classpath is distributed in the hope that it will be useful, but
  10. WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with GNU Classpath; see the file COPYING. If not, write to the
  15. Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  16. 02110-1301 USA.
  17. Linking this library statically or dynamically with other modules is
  18. making a combined work based on this library. Thus, the terms and
  19. conditions of the GNU General Public License cover the whole
  20. combination.
  21. As a special exception, the copyright holders of this library give you
  22. permission to link this library with independent modules to produce an
  23. executable, regardless of the license terms of these independent
  24. modules, and to copy and distribute the resulting executable under
  25. terms of your choice, provided that you also meet, for each linked
  26. independent module, the terms and conditions of the license of that
  27. module. An independent module is a module which is not derived from
  28. or based on this library. If you modify this library, you may extend
  29. this exception to your version of the library, but you are not
  30. obligated to do so. If you do not wish to do so, delete this
  31. exception statement from your version. */
  32. package java.lang;
  33. import java.io.Serializable;
  34. /**
  35. * <code>StringBuilder</code> represents a changeable <code>String</code>.
  36. * It provides the operations required to modify the
  37. * <code>StringBuilder</code>, including insert, replace, delete, append,
  38. * and reverse. It like <code>StringBuffer</code>, but is not
  39. * synchronized. It is ideal for use when it is known that the
  40. * object will only be used from a single thread.
  41. *
  42. * <p><code>StringBuilder</code>s are variable-length in nature, so even if
  43. * you initialize them to a certain size, they can still grow larger than
  44. * that. <em>Capacity</em> indicates the number of characters the
  45. * <code>StringBuilder</code> can have in it before it has to grow (growing
  46. * the char array is an expensive operation involving <code>new</code>).
  47. *
  48. * <p>Incidentally, compilers often implement the String operator "+"
  49. * by using a <code>StringBuilder</code> operation:<br>
  50. * <code>a + b</code><br>
  51. * is the same as<br>
  52. * <code>new StringBuilder().append(a).append(b).toString()</code>.
  53. *
  54. * <p>Classpath's StringBuilder is capable of sharing memory with Strings for
  55. * efficiency. This will help when a StringBuilder is converted to a String
  56. * and the StringBuilder is not changed after that (quite common when
  57. * performing string concatenation).
  58. *
  59. * @author Paul Fisher
  60. * @author John Keiser
  61. * @author Tom Tromey
  62. * @author Eric Blake (ebb9@email.byu.edu)
  63. * @see String
  64. * @see StringBuffer
  65. *
  66. * @since 1.5
  67. */
  68. public final class StringBuilder
  69. extends AbstractStringBuffer
  70. implements Serializable, CharSequence, Appendable
  71. {
  72. // Implementation note: if you change this class, you usually will
  73. // want to change StringBuffer as well.
  74. /**
  75. * For compatability with Sun's JDK
  76. */
  77. private static final long serialVersionUID = 4383685877147921099L;
  78. /**
  79. * Create a new StringBuilder with default capacity 16.
  80. */
  81. public StringBuilder()
  82. {
  83. super();
  84. }
  85. /**
  86. * Create an empty <code>StringBuilder</code> with the specified initial
  87. * capacity.
  88. *
  89. * @param capacity the initial capacity
  90. * @throws NegativeArraySizeException if capacity is negative
  91. */
  92. public StringBuilder(int capacity)
  93. {
  94. super(capacity);
  95. }
  96. /**
  97. * Create a new <code>StringBuilder</code> with the characters in the
  98. * specified <code>String</code>. Initial capacity will be the size of the
  99. * String plus 16.
  100. *
  101. * @param str the <code>String</code> to convert
  102. * @throws NullPointerException if str is null
  103. */
  104. public StringBuilder(String str)
  105. {
  106. super(str);
  107. }
  108. /**
  109. * Create a new <code>StringBuilder</code> with the characters in the
  110. * specified <code>CharSequence</code>. Initial capacity will be the
  111. * length of the sequence plus 16; if the sequence reports a length
  112. * less than or equal to 0, then the initial capacity will be 16.
  113. *
  114. * @param seq the initializing <code>CharSequence</code>
  115. * @throws NullPointerException if str is null
  116. */
  117. public StringBuilder(CharSequence seq)
  118. {
  119. super(seq);
  120. }
  121. /**
  122. * Get the length of the <code>String</code> this <code>StringBuilder</code>
  123. * would create. Not to be confused with the <em>capacity</em> of the
  124. * <code>StringBuilder</code>.
  125. *
  126. * @return the length of this <code>StringBuilder</code>
  127. * @see #capacity()
  128. * @see #setLength(int)
  129. */
  130. public int length()
  131. {
  132. return count;
  133. }
  134. /**
  135. * Get the total number of characters this <code>StringBuilder</code> can
  136. * support before it must be grown. Not to be confused with <em>length</em>.
  137. *
  138. * @return the capacity of this <code>StringBuilder</code>
  139. * @see #length()
  140. * @see #ensureCapacity(int)
  141. */
  142. public int capacity()
  143. {
  144. return value.length;
  145. }
  146. /**
  147. * Append the <code>String</code> value of the argument to this
  148. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  149. * to <code>String</code>.
  150. *
  151. * @param obj the <code>Object</code> to convert and append
  152. * @return this <code>StringBuilder</code>
  153. * @see String#valueOf(Object)
  154. * @see #append(String)
  155. */
  156. public StringBuilder append(Object obj)
  157. {
  158. super.append(obj);
  159. return this;
  160. }
  161. /**
  162. * Append the <code>String</code> to this <code>StringBuilder</code>. If
  163. * str is null, the String "null" is appended.
  164. *
  165. * @param str the <code>String</code> to append
  166. * @return this <code>StringBuilder</code>
  167. */
  168. public StringBuilder append(String str)
  169. {
  170. super.append(str);
  171. return this;
  172. }
  173. /**
  174. * Append the <code>StringBuilder</code> value of the argument to this
  175. * <code>StringBuilder</code>. This behaves the same as
  176. * <code>append((Object) stringBuffer)</code>, except it is more efficient.
  177. *
  178. * @param stringBuffer the <code>StringBuilder</code> to convert and append
  179. * @return this <code>StringBuilder</code>
  180. * @see #append(Object)
  181. */
  182. public StringBuilder append(StringBuffer stringBuffer)
  183. {
  184. super.append(stringBuffer);
  185. return this;
  186. }
  187. /**
  188. * Append the <code>char</code> array to this <code>StringBuilder</code>.
  189. * This is similar (but more efficient) than
  190. * <code>append(new String(data))</code>, except in the case of null.
  191. *
  192. * @param data the <code>char[]</code> to append
  193. * @return this <code>StringBuilder</code>
  194. * @throws NullPointerException if <code>str</code> is <code>null</code>
  195. * @see #append(char[], int, int)
  196. */
  197. public StringBuilder append(char[] data)
  198. {
  199. super.append(data, 0, data.length);
  200. return this;
  201. }
  202. /**
  203. * Append part of the <code>char</code> array to this
  204. * <code>StringBuilder</code>. This is similar (but more efficient) than
  205. * <code>append(new String(data, offset, count))</code>, except in the case
  206. * of null.
  207. *
  208. * @param data the <code>char[]</code> to append
  209. * @param offset the start location in <code>str</code>
  210. * @param count the number of characters to get from <code>str</code>
  211. * @return this <code>StringBuilder</code>
  212. * @throws NullPointerException if <code>str</code> is <code>null</code>
  213. * @throws IndexOutOfBoundsException if offset or count is out of range
  214. * (while unspecified, this is a StringIndexOutOfBoundsException)
  215. */
  216. public StringBuilder append(char[] data, int offset, int count)
  217. {
  218. super.append(data, offset, count);
  219. return this;
  220. }
  221. /**
  222. * Append the <code>String</code> value of the argument to this
  223. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  224. * to <code>String</code>.
  225. *
  226. * @param bool the <code>boolean</code> to convert and append
  227. * @return this <code>StringBuilder</code>
  228. * @see String#valueOf(boolean)
  229. */
  230. public StringBuilder append(boolean bool)
  231. {
  232. super.append(bool);
  233. return this;
  234. }
  235. /**
  236. * Append the <code>char</code> to this <code>StringBuilder</code>.
  237. *
  238. * @param ch the <code>char</code> to append
  239. * @return this <code>StringBuilder</code>
  240. */
  241. public StringBuilder append(char ch)
  242. {
  243. super.append(ch);
  244. return this;
  245. }
  246. /**
  247. * Append the characters in the <code>CharSequence</code> to this
  248. * buffer.
  249. *
  250. * @param seq the <code>CharSequence</code> providing the characters
  251. * @return this <code>StringBuilder</code>
  252. */
  253. public StringBuilder append(CharSequence seq)
  254. {
  255. super.append(seq, 0, seq.length());
  256. return this;
  257. }
  258. /**
  259. * Append some characters from the <code>CharSequence</code> to this
  260. * buffer. If the argument is null, the four characters "null" are
  261. * appended.
  262. *
  263. * @param seq the <code>CharSequence</code> providing the characters
  264. * @param start the starting index
  265. * @param end one past the final index
  266. * @return this <code>StringBuilder</code>
  267. */
  268. public StringBuilder append(CharSequence seq, int start,
  269. int end)
  270. {
  271. super.append(seq, start, end);
  272. return this;
  273. }
  274. /**
  275. * Append the <code>String</code> value of the argument to this
  276. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  277. * to <code>String</code>.
  278. *
  279. * @param inum the <code>int</code> to convert and append
  280. * @return this <code>StringBuilder</code>
  281. * @see String#valueOf(int)
  282. */
  283. // This is native in libgcj, for efficiency.
  284. public StringBuilder append(int inum)
  285. {
  286. super.append(inum);
  287. return this;
  288. }
  289. /**
  290. * Append the <code>String</code> value of the argument to this
  291. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  292. * to <code>String</code>.
  293. *
  294. * @param lnum the <code>long</code> to convert and append
  295. * @return this <code>StringBuilder</code>
  296. * @see String#valueOf(long)
  297. */
  298. public StringBuilder append(long lnum)
  299. {
  300. super.append(lnum);
  301. return this;
  302. }
  303. /**
  304. * Append the <code>String</code> value of the argument to this
  305. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  306. * to <code>String</code>.
  307. *
  308. * @param fnum the <code>float</code> to convert and append
  309. * @return this <code>StringBuilder</code>
  310. * @see String#valueOf(float)
  311. */
  312. public StringBuilder append(float fnum)
  313. {
  314. super.append(fnum);
  315. return this;
  316. }
  317. /**
  318. * Append the <code>String</code> value of the argument to this
  319. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  320. * to <code>String</code>.
  321. *
  322. * @param dnum the <code>double</code> to convert and append
  323. * @return this <code>StringBuilder</code>
  324. * @see String#valueOf(double)
  325. */
  326. public StringBuilder append(double dnum)
  327. {
  328. super.append(dnum);
  329. return this;
  330. }
  331. /**
  332. * Append the code point to this <code>StringBuilder</code>.
  333. * This is like #append(char), but will append two characters
  334. * if a supplementary code point is given.
  335. *
  336. * @param code the code point to append
  337. * @return this <code>StringBuilder</code>
  338. * @see Character#toChars(int, char[], int)
  339. * @since 1.5
  340. */
  341. public StringBuilder appendCodePoint(int code)
  342. {
  343. super.appendCodePoint(code);
  344. return this;
  345. }
  346. /**
  347. * Delete characters from this <code>StringBuilder</code>.
  348. * <code>delete(10, 12)</code> will delete 10 and 11, but not 12. It is
  349. * harmless for end to be larger than length().
  350. *
  351. * @param start the first character to delete
  352. * @param end the index after the last character to delete
  353. * @return this <code>StringBuilder</code>
  354. * @throws StringIndexOutOfBoundsException if start or end are out of bounds
  355. */
  356. public StringBuilder delete(int start, int end)
  357. {
  358. super.delete(start, end);
  359. return this;
  360. }
  361. /**
  362. * Delete a character from this <code>StringBuilder</code>.
  363. *
  364. * @param index the index of the character to delete
  365. * @return this <code>StringBuilder</code>
  366. * @throws StringIndexOutOfBoundsException if index is out of bounds
  367. */
  368. public StringBuilder deleteCharAt(int index)
  369. {
  370. super.deleteCharAt(index);
  371. return this;
  372. }
  373. /**
  374. * Replace characters between index <code>start</code> (inclusive) and
  375. * <code>end</code> (exclusive) with <code>str</code>. If <code>end</code>
  376. * is larger than the size of this StringBuilder, all characters after
  377. * <code>start</code> are replaced.
  378. *
  379. * @param start the beginning index of characters to delete (inclusive)
  380. * @param end the ending index of characters to delete (exclusive)
  381. * @param str the new <code>String</code> to insert
  382. * @return this <code>StringBuilder</code>
  383. * @throws StringIndexOutOfBoundsException if start or end are out of bounds
  384. * @throws NullPointerException if str is null
  385. */
  386. public StringBuilder replace(int start, int end, String str)
  387. {
  388. super.replace(start, end, str);
  389. return this;
  390. }
  391. /**
  392. * Creates a substring of this StringBuilder, starting at a specified index
  393. * and ending at the end of this StringBuilder.
  394. *
  395. * @param beginIndex index to start substring (base 0)
  396. * @return new String which is a substring of this StringBuilder
  397. * @throws StringIndexOutOfBoundsException if beginIndex is out of bounds
  398. * @see #substring(int, int)
  399. */
  400. public String substring(int beginIndex)
  401. {
  402. return substring(beginIndex, count);
  403. }
  404. /**
  405. * Creates a substring of this StringBuilder, starting at a specified index
  406. * and ending at one character before a specified index. This is implemented
  407. * the same as <code>substring(beginIndex, endIndex)</code>, to satisfy
  408. * the CharSequence interface.
  409. *
  410. * @param beginIndex index to start at (inclusive, base 0)
  411. * @param endIndex index to end at (exclusive)
  412. * @return new String which is a substring of this StringBuilder
  413. * @throws IndexOutOfBoundsException if beginIndex or endIndex is out of
  414. * bounds
  415. * @see #substring(int, int)
  416. */
  417. public CharSequence subSequence(int beginIndex, int endIndex)
  418. {
  419. return substring(beginIndex, endIndex);
  420. }
  421. /**
  422. * Creates a substring of this StringBuilder, starting at a specified index
  423. * and ending at one character before a specified index.
  424. *
  425. * @param beginIndex index to start at (inclusive, base 0)
  426. * @param endIndex index to end at (exclusive)
  427. * @return new String which is a substring of this StringBuilder
  428. * @throws StringIndexOutOfBoundsException if beginIndex or endIndex is out
  429. * of bounds
  430. */
  431. public String substring(int beginIndex, int endIndex)
  432. {
  433. int len = endIndex - beginIndex;
  434. if (beginIndex < 0 || endIndex > count || endIndex < beginIndex)
  435. throw new StringIndexOutOfBoundsException();
  436. if (len == 0)
  437. return "";
  438. return new String(value, beginIndex, len);
  439. }
  440. /**
  441. * Insert a subarray of the <code>char[]</code> argument into this
  442. * <code>StringBuilder</code>.
  443. *
  444. * @param offset the place to insert in this buffer
  445. * @param str the <code>char[]</code> to insert
  446. * @param str_offset the index in <code>str</code> to start inserting from
  447. * @param len the number of characters to insert
  448. * @return this <code>StringBuilder</code>
  449. * @throws NullPointerException if <code>str</code> is <code>null</code>
  450. * @throws StringIndexOutOfBoundsException if any index is out of bounds
  451. */
  452. public StringBuilder insert(int offset,
  453. char[] str, int str_offset, int len)
  454. {
  455. super.insert(offset, str, str_offset, len);
  456. return this;
  457. }
  458. /**
  459. * Insert the <code>String</code> value of the argument into this
  460. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  461. * to <code>String</code>.
  462. *
  463. * @param offset the place to insert in this buffer
  464. * @param obj the <code>Object</code> to convert and insert
  465. * @return this <code>StringBuilder</code>
  466. * @exception StringIndexOutOfBoundsException if offset is out of bounds
  467. * @see String#valueOf(Object)
  468. */
  469. public StringBuilder insert(int offset, Object obj)
  470. {
  471. super.insert(offset, obj);
  472. return this;
  473. }
  474. /**
  475. * Insert the <code>String</code> argument into this
  476. * <code>StringBuilder</code>. If str is null, the String "null" is used
  477. * instead.
  478. *
  479. * @param offset the place to insert in this buffer
  480. * @param str the <code>String</code> to insert
  481. * @return this <code>StringBuilder</code>
  482. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  483. */
  484. public StringBuilder insert(int offset, String str)
  485. {
  486. super.insert(offset, str);
  487. return this;
  488. }
  489. /**
  490. * Insert the <code>CharSequence</code> argument into this
  491. * <code>StringBuilder</code>. If the sequence is null, the String
  492. * "null" is used instead.
  493. *
  494. * @param offset the place to insert in this buffer
  495. * @param sequence the <code>CharSequence</code> to insert
  496. * @return this <code>StringBuilder</code>
  497. * @throws IndexOutOfBoundsException if offset is out of bounds
  498. */
  499. public StringBuilder insert(int offset, CharSequence sequence)
  500. {
  501. super.insert(offset, sequence);
  502. return this;
  503. }
  504. /**
  505. * Insert a subsequence of the <code>CharSequence</code> argument into this
  506. * <code>StringBuilder</code>. If the sequence is null, the String
  507. * "null" is used instead.
  508. *
  509. * @param offset the place to insert in this buffer
  510. * @param sequence the <code>CharSequence</code> to insert
  511. * @param start the starting index of the subsequence
  512. * @param end one past the ending index of the subsequence
  513. * @return this <code>StringBuilder</code>
  514. * @throws IndexOutOfBoundsException if offset, start,
  515. * or end are out of bounds
  516. */
  517. public StringBuilder insert(int offset, CharSequence sequence,
  518. int start, int end)
  519. {
  520. super.insert(offset, sequence, start, end);
  521. return this;
  522. }
  523. /**
  524. * Insert the <code>char[]</code> argument into this
  525. * <code>StringBuilder</code>.
  526. *
  527. * @param offset the place to insert in this buffer
  528. * @param data the <code>char[]</code> to insert
  529. * @return this <code>StringBuilder</code>
  530. * @throws NullPointerException if <code>data</code> is <code>null</code>
  531. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  532. * @see #insert(int, char[], int, int)
  533. */
  534. public StringBuilder insert(int offset, char[] data)
  535. {
  536. super.insert(offset, data);
  537. return this;
  538. }
  539. /**
  540. * Insert the <code>String</code> value of the argument into this
  541. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  542. * to <code>String</code>.
  543. *
  544. * @param offset the place to insert in this buffer
  545. * @param bool the <code>boolean</code> to convert and insert
  546. * @return this <code>StringBuilder</code>
  547. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  548. * @see String#valueOf(boolean)
  549. */
  550. public StringBuilder insert(int offset, boolean bool)
  551. {
  552. super.insert(offset, bool);
  553. return this;
  554. }
  555. /**
  556. * Insert the <code>char</code> argument into this <code>StringBuilder</code>.
  557. *
  558. * @param offset the place to insert in this buffer
  559. * @param ch the <code>char</code> to insert
  560. * @return this <code>StringBuilder</code>
  561. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  562. */
  563. public StringBuilder insert(int offset, char ch)
  564. {
  565. super.insert(offset, ch);
  566. return this;
  567. }
  568. /**
  569. * Insert the <code>String</code> value of the argument into this
  570. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  571. * to <code>String</code>.
  572. *
  573. * @param offset the place to insert in this buffer
  574. * @param inum the <code>int</code> to convert and insert
  575. * @return this <code>StringBuilder</code>
  576. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  577. * @see String#valueOf(int)
  578. */
  579. public StringBuilder insert(int offset, int inum)
  580. {
  581. super.insert(offset, inum);
  582. return this;
  583. }
  584. /**
  585. * Insert the <code>String</code> value of the argument into this
  586. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  587. * to <code>String</code>.
  588. *
  589. * @param offset the place to insert in this buffer
  590. * @param lnum the <code>long</code> to convert and insert
  591. * @return this <code>StringBuilder</code>
  592. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  593. * @see String#valueOf(long)
  594. */
  595. public StringBuilder insert(int offset, long lnum)
  596. {
  597. super.insert(offset, lnum);
  598. return this;
  599. }
  600. /**
  601. * Insert the <code>String</code> value of the argument into this
  602. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  603. * to <code>String</code>.
  604. *
  605. * @param offset the place to insert in this buffer
  606. * @param fnum the <code>float</code> to convert and insert
  607. * @return this <code>StringBuilder</code>
  608. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  609. * @see String#valueOf(float)
  610. */
  611. public StringBuilder insert(int offset, float fnum)
  612. {
  613. super.insert(offset, fnum);
  614. return this;
  615. }
  616. /**
  617. * Insert the <code>String</code> value of the argument into this
  618. * <code>StringBuilder</code>. Uses <code>String.valueOf()</code> to convert
  619. * to <code>String</code>.
  620. *
  621. * @param offset the place to insert in this buffer
  622. * @param dnum the <code>double</code> to convert and insert
  623. * @return this <code>StringBuilder</code>
  624. * @throws StringIndexOutOfBoundsException if offset is out of bounds
  625. * @see String#valueOf(double)
  626. */
  627. public StringBuilder insert(int offset, double dnum)
  628. {
  629. super.insert(offset, dnum);
  630. return this;
  631. }
  632. /**
  633. * Reverse the characters in this StringBuilder. The same sequence of
  634. * characters exists, but in the reverse index ordering.
  635. *
  636. * @return this <code>StringBuilder</code>
  637. */
  638. public StringBuilder reverse()
  639. {
  640. super.reverse();
  641. return this;
  642. }
  643. /**
  644. * Convert this <code>StringBuilder</code> to a <code>String</code>. The
  645. * String is composed of the characters currently in this StringBuilder. Note
  646. * that the result is a copy, and that future modifications to this buffer
  647. * do not affect the String.
  648. *
  649. * @return the characters in this StringBuilder
  650. */
  651. public String toString()
  652. {
  653. return new String(this);
  654. }
  655. }