Skip to content
Reference > Classes

StringBuilder

Definition

StringBuilder var = .... ;

Extends

Extended By

None

Description

A mutable sequence of characters

Method Summary

Owner Name Return Type Description
StringBuilder constructor() StringBuilder Initialize a StringBuilder object
StringBuilder constructor(s) StringBuilder Initialize a StringBuilder object with the same characters as the string provided
StringBuilder constructor(capacity) StringBuilder Initialize a StringBuilder object with an initial capacity
StringBuilder append(value) StringBuilder Appends the object to the StringBuilder
StringBuilder clear() StringBuilder Clears the StringBuilder
StringBuilder delete(start, end) StringBuilder Deletes the characters in the range from the StringBuidler
StringBuilder deleteCharAt(offset) StringBuilder Delete the char at the offset in the StringBuilder
StringBuilder ensureCapacity(capacity) StringBuilder Ensures the capacity of the Stringbuilder is at a minimum the specified capacity
StringBuilder getCapacity() Integer Get the capcity of the StringBuilder
StringBuilder getCharAt(offset) Character Returns the char at the offset in the Stringbuilder
Object getClassName() String Returns the string name of this object's class type.
StringBuilder insert(offset, value) StringBuilder Inserts the object to the StringBuilder at an offset
StringBuilder length() Integer Get the length of the StringBuilder
StringBuilder reverse() StringBuilder Reverses the character sequence in the StringBuilder
StringBuilder setCharAt(offset, char) StringBuilder Set the char at the offset in the StringBuilder
StringBuilder splice(start, end, value) StringBuilder Splice and replace the characters in the range from the StringBuidler with the value
StringBuilder substring(start, end) String Returns the substring within the range of StringBuilder
Object toJson() String Returns a string of a json representation of this object.
StringBuilder toString() String Evaluates StringBuilder to a String
StringBuilder toStringAndClear() String Evaluates StringBuilder to a String and clears it
StringBuilder trimCapacity() StringBuilder Tries to reduce the capacity of the StringBuilder if the capacity is currently larger than necessary

Method Definitions


constructor()

StringBuilder stringbuilder = new StringBuilder()

Description

Initialize a StringBuilder object

Example 1

1
2
3
StringBuilder sb = new StringBuilder();

// sb.toJson() = ""

Initializes an empty StringBuilder. The toJson shows the current contents of the StringBuilder.


constructor(s)

StringBuilder stringbuilder = new StringBuilder(Object s)

Description

Initialize a StringBuilder object with the same characters as the string provided

Parameter Definition

Name Type Description
s Object  a String

Example 1

1
2
3
StringBuilder sb = new StringBuilder("3f");

// sb.toJson() = "3f"

constructor(capacity)

StringBuilder stringbuilder = new StringBuilder(Integer capacity)

Description

Initialize a StringBuilder object with an initial capacity

Parameter Definition

Name Type Description
capacity Integer  int capacity

Example 1

1
2
3
StringBuilder sb = new StringBuilder(1);

// sb.getCapacity() = 1

append(value)

StringBuilder StringBuilder::append(Object value)

Description

Appends the object to the StringBuilder

Parameter Definition

Name Type Description
value Object  value to append

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder();
sb.append("3forge");

// sb.toJson() = "3forge"

clear()

StringBuilder StringBuilder::clear()

Description

Clears the StringBuilder

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.clear();

// sb.toJson() = ""

delete(start,end)

StringBuilder StringBuilder::delete(Integer start, Integer end)

Description

Deletes the characters in the range from the StringBuidler

Parameter Definition

Name Type Description
start Integer  start position inclusive
end Integer  end position exclusive

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.delete(2,6);

// sb.toJson() = "3f"

deleteCharAt(offset)

StringBuilder StringBuilder::deleteCharAt(Integer offset)

Description

Delete the char at the offset in the StringBuilder

Parameter Definition

Name Type Description
offset Integer  offset/index of string to delete character from

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forgee");
sb.deleteCharAt(6);

// sb.toJson() = "3forge"

ensureCapacity(capacity)

StringBuilder StringBuilder::ensureCapacity(Integer capacity)

Description

Ensures the capacity of the Stringbuilder is at a minimum the specified capacity

Parameter Definition

Name Type Description
capacity Integer  minimum capacity

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder(0);
sb.ensureCapacity(100);

// sb.getCapacity() = 100

getCapacity()

Integer StringBuilder::getCapacity()

Description

Get the capcity of the StringBuilder

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder();
sb.getCapacity();

// sb.getCapacity() = 16

getCharAt(offset)

Character StringBuilder::getCharAt(Integer offset)

Description

Returns the char at the offset in the Stringbuilder

Parameter Definition

Name Type Description
offset Integer  offset/index to get character at

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.getCharAt(0);

// sb.getCharAt(0) = 3

getClassName()

String Object::getClassName()

Description

Returns the string name of this object's class type.

Example 20

1
2
3
4
StringBuilder sb = new StringBuilder();
sb.getClassName();

// sb.getClassName() = StringBuilder

insert(offset,value)

StringBuilder StringBuilder::insert(Integer offset, Object value)

Description

Inserts the object to the StringBuilder at an offset

Parameter Definition

Name Type Description
offset Integer  offset to insert at
value Object  value to append

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.insert(6," LLC");

// sb.toJson() = "3forge LLC"

length()

Integer StringBuilder::length()

Description

Get the length of the StringBuilder

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.length();

// sb.length() = 6

reverse()

StringBuilder StringBuilder::reverse()

Description

Reverses the character sequence in the StringBuilder

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.reverse();

// sb.toJson() = "egrof3"

setCharAt(offset,char)

StringBuilder StringBuilder::setCharAt(Integer offset, Character char)

Description

Set the char at the offset in the StringBuilder

Parameter Definition

Name Type Description
offset Integer  offset/index of string
char Character  character to set

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3Forge");
sb.setCharAt(1,'f');

// sb.toJson() = "3forge"

splice(start,end,value)

StringBuilder StringBuilder::splice(Integer start, Integer end, Object value)

Description

Splice and replace the characters in the range from the StringBuidler with the value

Parameter Definition

Name Type Description
start Integer  start position inclusive
end Integer  end position exclusive
value Object  value to replace with

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3 Forge");
sb.splice(0,3,"3f");

// sb.toJson() = "3forge"

substring(start,end)

String StringBuilder::substring(Integer start, Integer end)

Description

Returns the substring within the range of StringBuilder

Parameter Definition

Name Type Description
start Integer  start position inclusive
end Integer  end position exclusive

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
sb.substring(1,6);

// sb.substring(1,6) = forge

toJson()

String Object::toJson()

Description

Returns a string of a json representation of this object.

Example 20

1
2
3
4
StringBuilder sb = new StringBuilder();
sb.toJson();

// sb.toJson() = ""

toString()

String StringBuilder::toString()

Description

Evaluates StringBuilder to a String

Example 1

1
2
3
4
StringBuilder sb = new StringBuilder("3forge");
String s = sb.toString();

// s = 3forge

toStringAndClear()

String StringBuilder::toStringAndClear()

Description

Evaluates StringBuilder to a String and clears it

Example 1

1
2
3
4
5
StringBuilder sb = new StringBuilder("3forge");
String s = sb.toStringAndClear();

// s = 3forge
// sb.toJson() = ""

trimCapacity()

StringBuilder StringBuilder::trimCapacity()

Description

Tries to reduce the capacity of the StringBuilder if the capacity is currently larger than necessary

Example 1

1
2
3
4
5
StringBuilder sb = new StringBuilder(100);
sb.append("3f");
sb.trimCapacity();

// sb.getCapacity() = 2