public final class StringBuffer4D
extends java.lang.Object
"a" + 4 + "c"is compiled to:
new StringBuffer().append("a").append(4).append("c").toString()... to concatenate multiple strings together. In the code shown, the compiler generates references to the StringBuffer class to append the objects together.
If you use it in loop, consider creating a new StringBuffer with an initial number of characters, and calling setLength before each use. This can improve the performance up to 10x. Example:
StringBuffer sb = new StringBuffer(1024); for (...) { sb.setLength(0); sb.append(...).append(...).append(...); String s = sb.toString(); }IMPORTANT: the totalcross.lang package is the java.lang that will be used in the device. You CANNOT use nor import totalcross.lang package in desktop. When tc.Deploy is called, all references to java.lang are replaced by totalcross.lang automatically. Given this, you must use only the classes and methods that exists BOTH in java.lang and totalcross.lang. For example, you can't use java.lang.ClassLoader because there are no totalcross.lang.ClassLoader. Another example, you can't use java.lang.String.indexOfIgnoreCase because there are no totalcross.lang.String.indexOfIgnoreCase method. Trying to use a class or method from the java.lang package that has no correspondence with totalcross.lang will make the tc.Deploy program to abort, informing where the problem occured. A good idea is to always refer to this javadoc to know what is and what isn't available.
Modifier and Type | Field and Description |
---|---|
static int |
STARTING_SIZE |
Constructor and Description |
---|
StringBuffer4D()
Constructs an empty String buffer.
|
StringBuffer4D(int length)
Constructs an empty String buffer with the specified initial length.
|
StringBuffer4D(String4D str)
Constructs a String buffer with the specified initial buffer.
|
Modifier and Type | Method and Description |
---|---|
StringBuffer4D |
append(boolean b)
Appends a boolean to the end of this buffer.
|
StringBuffer4D |
append(char c)
Appends a character to the end of this buffer.
|
StringBuffer4D |
append(char[] str)
Appends an array of characters to the end of this buffer.
|
StringBuffer4D |
append(char[] str,
int offset,
int len)
Appends a range of an array of characters to the end of this buffer.
|
StringBuffer4D |
append(java.lang.CharSequence seq) |
StringBuffer4D |
append(java.lang.CharSequence seq,
int start,
int end) |
StringBuffer4D |
append(double d)
Appends a double to the end of this buffer.
|
StringBuffer4D |
append(int i)
Appends an integer to the end of this buffer.
|
StringBuffer4D |
append(long l)
Appends a long to the end of this buffer.
|
StringBuffer4D |
append(java.lang.Object obj)
Appends an object to the end of this buffer.
|
StringBuffer4D |
append(java.lang.String str)
Appends a String to the end of this buffer.
|
StringBuffer4D |
append(StringBuffer4D stringBuffer)
Append the
StringBuffer4D value of the argument to this
StringBuffer4D . |
StringBuffer4D |
append(java.lang.String str,
int start,
int end)
Appends a String to the end of this buffer.
|
int |
capacity()
Returns the current capacity of the String buffer.
|
char |
charAt(int index)
Returns the character at the specified index.
|
StringBuffer4D |
delete4D(int start,
int end)
Removes the characters in a substring of this
StringBuffer . |
StringBuffer4D |
deleteCharAt(int index)
Delete a character from this
StringBuffer4D . |
void |
ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least equal to the
specified minimum.
|
void |
getChars(int srcBegin,
int srcEnd,
char[] dst,
int dstBegin)
Copies the characters of the specified substring (determined by
srcBegin and srcEnd) into the character array, starting at the
array's dstBegin location.
|
int |
indexOf(String4D str)
Finds the first instance of a substring in this StringBuilder.
|
int |
indexOf(String4D str,
int fromIndex)
Finds the first instance of a String in this StringBuffer, starting at
a given index.
|
StringBuffer4D |
insert(int offset,
boolean bool)
Insert the
String value of the argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
char ch)
Insert the
char argument into this StringBuffer4D . |
StringBuffer4D |
insert(int offset,
char[] data)
Insert the
char[] argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
char[] str,
int str_offset,
int len)
Insert a subarray of the
char[] argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
double dnum)
Insert the
String value of the argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
int inum)
Insert the
String value of the argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
long lnum)
Insert the
String value of the argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
java.lang.Object obj)
Insert the
String value of the argument into this
StringBuffer4D . |
StringBuffer4D |
insert(int offset,
String4D str)
Insert the
String argument into this
StringBuffer4D . |
int |
lastIndexOf(String4D str)
Finds the last instance of a substring in this StringBuffer.
|
int |
lastIndexOf(String4D str,
int fromIndex)
Finds the last instance of a String in this StringBuffer, starting at a
given index.
|
int |
length()
Returns the number of characters in the buffer.
|
StringBuffer4D |
replace(int start,
int end,
String4D str)
Replace characters between index
start (inclusive) and
end (exclusive) with str . |
StringBuffer4D |
reverse()
Reverses the string.
|
void |
setCharAt(int index,
char ch)
Replaces the char at the given index.
|
void |
setLength(int newLength)
Sets the length of the String.
|
String4D |
substring(int beginIndex)
Creates a substring of this StringBuffer4D, starting at a specified index
and ending at the end of this StringBuffer4D.
|
String4D |
substring(int beginIndex,
int endIndex)
Creates a substring of this StringBuffer4D, starting at a specified index
and ending at one character before a specified index.
|
java.lang.String |
toString()
Converts to a String representing the data in the buffer.
|
public static final int STARTING_SIZE
public StringBuffer4D()
public StringBuffer4D(int length)
length
- the initial lengthpublic StringBuffer4D(String4D str)
str
- the initial buffer of the bufferpublic int length()
public void setCharAt(int index, char ch)
public int capacity()
public void ensureCapacity(int minimumCapacity)
minimumCapacity
- the minimum desired capacity in characterspublic void setLength(int newLength)
newLength
- the new length of the bufferpublic char charAt(int index)
index
- the index of the desired characterpublic void getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin)
srcBegin
- begin copy at this offset in the StringsrcEnd
- stop copying at this offset in the Stringdst
- the array to copy the data intodstBegin
- offset into dstpublic StringBuffer4D append(java.lang.Object obj)
obj
- the object to be appendedpublic StringBuffer4D append(java.lang.String str)
str
- the String to be appendedpublic StringBuffer4D append(java.lang.String str, int start, int end)
str
- the String that has a part to be appendedstart
- the start index of the substring to be appendedend
- the end index of the Substring to be appendedpublic StringBuffer4D append(java.lang.CharSequence seq)
public StringBuffer4D append(java.lang.CharSequence seq, int start, int end)
public StringBuffer4D append(char[] str)
str
- the characters to be appendedpublic StringBuffer4D append(char[] str, int offset, int len)
str
- the characters to be appendedoffset
- where to startlen
- the number of characters to addpublic StringBuffer4D append(boolean b)
b
- the boolean to be appendedpublic StringBuffer4D append(char c)
c
- the character to be appendedpublic StringBuffer4D append(int i)
i
- the integer to be appendedpublic StringBuffer4D append(long l)
l
- the long to be appendedpublic StringBuffer4D append(double d)
d
- the double to be appendedpublic java.lang.String toString()
toString
in class java.lang.Object
public StringBuffer4D delete4D(int start, int end)
StringBuffer
.
The substring begins at the specified start
and extends to
the character at index end - 1
or to the end of the
StringBuffer
if no such character exists. If
start
is equal to end
, no changes are made.
If any paramter goes beyond limits, it is enforced into limits.
If start > end, the string is emptied;
Returns this
StringBuffer.public StringBuffer4D reverse()
public StringBuffer4D append(StringBuffer4D stringBuffer)
StringBuffer4D
value of the argument to this
StringBuffer4D
. This behaves the same as
append((Object) stringBuffer)
, except it is more efficient.stringBuffer
- the StringBuffer4D
to convert and appendStringBuffer4D
append(Object)
public StringBuffer4D deleteCharAt(int index)
StringBuffer4D
.index
- the index of the character to deleteStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if index is out of boundspublic StringBuffer4D replace(int start, int end, String4D str)
start
(inclusive) and
end
(exclusive) with str
. If end
is larger than the size of this StringBuffer4D, all characters after
start
are replaced.start
- the beginning index of characters to delete (inclusive)end
- the ending index of characters to delete (exclusive)str
- the new String
to insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if start or end are out of boundsjava.lang.NullPointerException
- if str is nullpublic String4D substring(int beginIndex)
beginIndex
- index to start substring (base 0)java.lang.StringIndexOutOfBoundsException
- if beginIndex is out of boundssubstring(int, int)
public String4D substring(int beginIndex, int endIndex)
beginIndex
- index to start at (inclusive, base 0)endIndex
- index to end at (exclusive)java.lang.StringIndexOutOfBoundsException
- if beginIndex or endIndex is out
of boundspublic StringBuffer4D insert(int offset, char[] str, int str_offset, int len)
char[]
argument into this
StringBuffer4D
.offset
- the place to insert in this bufferstr
- the char[]
to insertstr_offset
- the index in str
to start inserting fromlen
- the number of characters to insertStringBuffer4D
java.lang.NullPointerException
- if str
is null
java.lang.StringIndexOutOfBoundsException
- if any index is out of boundspublic StringBuffer4D insert(int offset, java.lang.Object obj)
String
value of the argument into this
StringBuffer4D
. Uses String.valueOf()
to convert
to String
.offset
- the place to insert in this bufferobj
- the Object
to convert and insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundsString.valueOf(Object)
public StringBuffer4D insert(int offset, String4D str)
String
argument into this
StringBuffer4D
. If str is null, the String "null" is used
instead.offset
- the place to insert in this bufferstr
- the String
to insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundspublic StringBuffer4D insert(int offset, char[] data)
char[]
argument into this
StringBuffer4D
.offset
- the place to insert in this bufferdata
- the char[]
to insertStringBuffer4D
java.lang.NullPointerException
- if data
is null
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundsinsert(int, char[], int, int)
public StringBuffer4D insert(int offset, boolean bool)
String
value of the argument into this
StringBuffer4D
. Uses String.valueOf()
to convert
to String
.offset
- the place to insert in this bufferbool
- the boolean
to convert and insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundsString.valueOf(boolean)
public StringBuffer4D insert(int offset, char ch)
char
argument into this StringBuffer4D
.offset
- the place to insert in this bufferch
- the char
to insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundspublic StringBuffer4D insert(int offset, int inum)
String
value of the argument into this
StringBuffer4D
. Uses String.valueOf()
to convert
to String
.offset
- the place to insert in this bufferinum
- the int
to convert and insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundsString.valueOf(int)
public StringBuffer4D insert(int offset, long lnum)
String
value of the argument into this
StringBuffer4D
. Uses String.valueOf()
to convert
to String
.offset
- the place to insert in this bufferlnum
- the long
to convert and insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundsString.valueOf(long)
public StringBuffer4D insert(int offset, double dnum)
String
value of the argument into this
StringBuffer4D
. Uses String.valueOf()
to convert
to String
.offset
- the place to insert in this bufferdnum
- the double
to convert and insertStringBuffer4D
java.lang.StringIndexOutOfBoundsException
- if offset is out of boundsString.valueOf(double)
public int indexOf(String4D str)
str
- String to findjava.lang.NullPointerException
- if str is nullpublic int indexOf(String4D str, int fromIndex)
str
- String to findfromIndex
- index to start the searchjava.lang.NullPointerException
- if str is nullpublic int lastIndexOf(String4D str)
str
- String to findjava.lang.NullPointerException
- if str is nullpublic int lastIndexOf(String4D str, int fromIndex)
str
- String to findfromIndex
- index to start the searchjava.lang.NullPointerException
- if str is null