Java String Indent Format indent(StringBuilder builder, int times)

Here you can find the source of indent(StringBuilder builder, int times)

Description

Does the same thing as #indent(int) but appends it directly to string builder.

License

Open Source License

Declaration

public static void indent(StringBuilder builder, int times) 

Method Source Code

//package com.java2s;
/*/* www .j  a v a  2  s.c  o  m*/
 * Copyright 2013 Red Hat, Inc. and/or its affiliates.
 *
 * Licensed under the Eclipse Public License version 1.0, available at
 * http://www.eclipse.org/legal/epl-v10.html
 */

public class Main {
    public static final String INDENT = "    ";

    /**
     * Does the same thing as {@link #indent(int)} but appends it directly to string builder.
     */
    public static void indent(StringBuilder builder, int times) {
        for (int i = 0; i < times; i++) {
            builder.append(INDENT);
        }
    }

    /**
     * Returns {@link #INDENT} "times" times.
     */
    public static String indent(int times) {
        StringBuilder builder = new StringBuilder(INDENT.length() * times);
        indent(builder, times);
        return builder.toString();
    }
}

Related

  1. indent(StringBuffer sb, int indentLevel)
  2. indent(StringBuilder b, int i)
  3. indent(StringBuilder buffer, int d)
  4. indent(StringBuilder builder, int indent)
  5. indent(StringBuilder builder, int indent)
  6. indent(StringBuilder sb, int indent)
  7. indent(StringBuilder sb, int indent)
  8. indent2(String text, String indent)
  9. indentAllLines(String s, String indent)