append In New Line to StringBuilder - Java java.lang

Java examples for java.lang:StringBuilder

Description

append In New Line to StringBuilder

Demo Code


//package com.java2s;

public class Main {
    public static void main(String[] argv) throws Exception {
        StringBuilder out = new StringBuilder();
        String name = "java2s.com";
        String text = "java2s.com";
        appendInNewLine(out, name, text);
    }/*from   www . ja  v a2  s  . c  om*/

    public static void appendInNewLine(StringBuilder out, String name,
            String text) {
        appendInNewLine(out, name, text, "");
    }

    public static void appendInNewLine(StringBuilder out, String name,
            String text, String suffix) {
        if (text.isEmpty())
            return;

        if (out.length() > 0)
            out.append("\n");

        out.append(name).append(": ").append(text).append(suffix);
    }
}

Related Tutorials