Example usage for java.lang StringBuilder append

List of usage examples for java.lang StringBuilder append

Introduction

In this page you can find the example usage for java.lang StringBuilder append.

Prototype

@Override
    public StringBuilder append(double d) 

Source Link

Usage

From source file:Main.java

public static String formatShortDuration(int seconds) {
    int hours = seconds / 3600;
    int minutes = (seconds % 3600) / 60;
    int secondRemainder = seconds % 60;
    StringBuilder sb = new StringBuilder();
    if (hours > 0) {
        sb.append(hours);
        sb.append(":");
    }/*from   w  ww.j  a va2  s.  c o  m*/
    if (minutes < 10)
        sb.append('0');
    sb.append(minutes);
    sb.append(":");
    if (secondRemainder < 10)
        sb.append('0');
    sb.append(secondRemainder);

    return sb.toString();
}

From source file:Main.java

public static String getRandomNumString(int length) {
    StringBuilder builder = new StringBuilder();
    for (int i = 0; i < length; i++) {
        builder.append(String.valueOf((int) (Math.random() * 10)));
    }//  w  w w . j a  va 2  s  .  co  m
    return builder.toString();
}

From source file:Main.java

public static String createXSLT(String xpathExpression, String transformation) {
    StringBuilder stylesheet = new StringBuilder();

    stylesheet.append("<?xml version='1.0'?>\n");
    stylesheet.append("<xsl:stylesheet version=\"1.0\"\n");
    stylesheet.append("\txmlns:xsl=\"http://www.w3.org/1999/XSL/Transform\" >\n");
    stylesheet.append("\t<xsl:output omit-xml-declaration=\"no\" indent=\"yes\"/>\n\n");

    stylesheet.append("\t<xsl:template match=\"@* | node()\">\n");
    stylesheet.append("\t\t<xsl:copy>\n");
    stylesheet.append("\t\t\t<xsl:apply-templates select=\"@* | node()\" />\n");
    stylesheet.append("\t\t</xsl:copy>\n");
    stylesheet.append("\t</xsl:template>\n");
    stylesheet.append("\t<xsl:template match=\"").append(xpathExpression).append("\">\n");

    stylesheet.append(transformation);//ww  w  .  j  a va  2 s . c  o m

    stylesheet.append("\t</xsl:template>\n");

    stylesheet.append("</xsl:stylesheet>\n");
    return stylesheet.toString();
}

From source file:Main.java

public static void emptyTag(StringBuilder stringBuilder, String tagname, String... attributes) {
    stringBuilder.append('<');
    stringBuilder.append(tagname);/*from   w w  w.ja  v a  2  s . c o  m*/
    stringBuilder.append(' ');

    for (int i = 0; i < attributes.length; i += 2) {
        stringBuilder.append(attributes[i]);
        stringBuilder.append("=\"");
        stringBuilder.append(attributes[i + 1]);
        stringBuilder.append("\" ");
    }

    stringBuilder.append("/>");
}

From source file:Main.java

public static String addStringsWithSpaces(Object... params) {
    StringBuilder stringBuilder = new StringBuilder();
    for (Object s : params) {
        stringBuilder.append(s);
        stringBuilder.append(" ");
    }// ww  w  .  j a v a2  s.  c  om
    return stringBuilder.toString();

}

From source file:Main.java

public static String integerListToString(List<Integer> list, String segmentation) {
    if (isEmpty(list)) {
        return null;
    }/*  w ww  .  j  a  va  2s.co m*/

    StringBuilder sb = new StringBuilder();
    for (int i : list) {
        sb.append(segmentation);
        sb.append(i);
    }

    return sb.substring(segmentation.length());
}

From source file:Main.java

public static String toString(List<?> col) {
    StringBuilder buf = new StringBuilder();
    buf.append("[");
    boolean first = true;
    for (Object o : col) {
        if (first) {
            first = false;/*from  w  ww  .j  a  va 2 s .  c  om*/
        } else {
            buf.append(", ");
        }
        buf.append(o.toString());
    }
    buf.append("]");
    return buf.toString();
}

From source file:Main.java

public static String toString(Map<?, ?> col) {
    StringBuilder buf = new StringBuilder();
    buf.append("[");
    boolean first = true;
    for (Map.Entry<?, ?> o : col.entrySet()) {
        if (first) {
            first = false;//from   w  ww .  ja va 2  s. co m
        } else {
            buf.append(", ");
        }
        buf.append(o.getKey().toString()).append(" : ").append(o.getValue().toString());
    }
    buf.append("]");
    return buf.toString();
}

From source file:Main.java

public static String makeHtmlSpace(int number) {
    final String space = "&nbsp;";
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < number; i++) {
        result.append(space);
    }/*from   w w  w .ja  v  a  2s .c  om*/
    return result.toString();
}

From source file:Main.java

public static String toHexString(byte[] bytes, String pad) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < bytes.length; i++) {
        sb.append(String.format("%02x%s", bytes[i], pad));
    }//from   w  ww .  j ava 2 s .co m
    return sb.toString();
}