Java Utililty Methods String Indent Format

List of utility methods to do String Indent Format

Description

The list of methods to do String Indent Format are organized into topic(s).

Method

voidindent(StringBuilder builder, int indent)
indent
for (int loop = 0; loop < indent; loop++) {
    builder.append("   ");
voidindent(StringBuilder builder, int times)
Does the same thing as #indent(int) but appends it directly to string builder.
for (int i = 0; i < times; i++) {
    builder.append(INDENT);
StringBuilderindent(StringBuilder sb, int indent)
indent
return indent(sb, indent, '\t');
StringBuilderindent(StringBuilder sb, int indent)
indent
for (int i = 0; i < indent; ++i)
    sb.append(' ');
return sb;
Stringindent2(String text, String indent)
Indents all but the first line using the given indent string.
if (text == null)
    return "";
int n = text.length();
StringBuilder result = new StringBuilder(n * 2);
for (int i = 0; i < n; ++i) {
    char ch = text.charAt(i);
    result.append(ch);
    switch (ch) {
...
StringBuilderindentAllLines(String s, String indent)
indent All Lines
StringBuilder sb = new StringBuilder();
String delimiter = "";
for (String line : s.split("\n")) {
    sb.append(delimiter).append(indent).append(line);
    delimiter = "\n";
return sb;
Stringindentation(int howMany)
indentation
if (howMany > 0)
    return String.format("%1$" + howMany + "s", " ");
else
    return "";
Stringindentation(int numberOfIndent)
indentation
StringBuilder builder = new StringBuilder();
for (int i = 0; i < numberOfIndent; i++) {
    builder.append("\t");
return builder.toString();
intindentationLevel(CharSequence c)
indentation Level
int i = 0;
while (i < c.length() && c.charAt(i) == ' ') {
    i++;
return i;
StringindentationStringOfCursorLine(String text, int cursor)
indentation String Of Cursor Line
int lineStart = startColOfCursorLine(text, cursor);
int firstCharAt = lineStart;
while (firstCharAt < text.length()) {
    if (text.charAt(firstCharAt) != ' ') {
        break;
    ++firstCharAt;
return text.substring(lineStart, firstCharAt);