MCPcopy Index your code
hub / github.com/codenameone/CodenameOne / StringBuilder

Class StringBuilder

vm/JavaAPI/src/java/lang/StringBuilder.java:36–644  ·  view source on GitHub ↗

A string builder implements a mutable sequence of characters. A string builder is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. String builders are n

Source from the content-addressed store, hash-verified

34 * Since: JDK1.0, CLDC 1.0 See Also:ByteArrayOutputStream, String
35 */
36public final class StringBuilder implements CharSequence, Appendable {
37 static final int INITIAL_CAPACITY = 16;
38
39 private char[] value;
40
41 private int count;
42
43 //private boolean shared;
44
45 /**
46 * Constructs a string builder with no characters in it and an initial capacity of 16 characters.
47 */
48 public StringBuilder(){
49 value = new char[INITIAL_CAPACITY];
50 }
51
52 /**
53 * Constructs a string builder with no characters in it and an initial capacity specified by the length argument.
54 * length - the initial capacity.
55 * - if the length argument is less than 0.
56 */
57 public StringBuilder(int length){
58 if (length < 0) {
59 throw new NegativeArraySizeException(Integer.toString(length));
60 }
61 value = new char[length];
62 }
63
64 /**
65 * Constructs a string builder so that it represents the same sequence of characters as the string argument; in other words, the initial contents of the string builder is a copy of the argument string. The initial capacity of the string builder is 16 plus the length of the string argument.
66 * str - the initial contents of the builder.
67 */
68 public StringBuilder(java.lang.String str){
69 count = str.length();
70 //shared = false;
71 value = new char[count + INITIAL_CAPACITY];
72 str.getChars(0, count, value, 0);
73 }
74
75 public StringBuilder(CharSequence str){
76 this(str.toString());
77 }
78
79 private StringIndexOutOfBoundsException failedBoundsCheck(int arrayLength, int offset, int count) {
80 throw new StringIndexOutOfBoundsException(count);
81 }
82
83 /*
84 * Allocates new array with characters from 'data', starting at 'offset', and with length charCount.
85 * Pretty much the same implementation as String(char[] data, int offset, int charCount) in ./String.java
86 * throws failedBundsCheck() if the new string tries to take characters outside the range of 'data'
87 */
88 private StringBuilder(char[] data, int offset, int charCount) {
89 if((offset | charCount) < 0 || charCount > data.length - offset) {
90 throw failedBoundsCheck(data.length, offset, charCount);
91 }
92 this.value = new char[charCount];
93 this.count = charCount;

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected