Example usage for java.lang StringBuilder toString

List of usage examples for java.lang StringBuilder toString

Introduction

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

Prototype

@Override
    @HotSpotIntrinsicCandidate
    public String toString() 

Source Link

Usage

From source file:Main.java

/** Join into string */
public static String join(List<String> x) {
    StringBuilder sb = new StringBuilder();
    for (String token : x) {
        sb.append(token).append(" ");
    }/*from   w  ww. j  a v  a  2 s.c  o  m*/
    return sb.toString().trim();
}

From source file:Main.java

/**
 * devuelve el texto enmarcado en una etiqueta. Este m&eacute;todo funciona correctamente en el caso de que la etiqueta no tenga
 * multiplicidad. En el caso de que tuviera multiplicidad devolver&iacute;a &uacute;nicamente el prime contenido que se encuentre.
 * @param etiqueta etiqueta de la que queremos extraer su texto
 * @param documento: documento o subdocumento donde esta definida la etiqueta de la cual queremos extraer su texto
 * @return String Contenido de la etiqueta. En el caso de que la etiqueta no existiera devuelve <code>null</code>
 *///from w w  w  . j ava2 s  .  c  o  m
public static String dameTextoDeLaEtiqueta(String etiqueta, String documento) {
    StringBuilder sb = new StringBuilder("<");
    sb.append(etiqueta).append("/>");
    if (documento.indexOf(sb.toString()) != -1)
        return "";
    sb = new StringBuilder("<");
    sb.append(etiqueta).append(">");
    int posEtiquetaApertura = documento.indexOf(sb.toString());
    if (posEtiquetaApertura == -1)
        return null;
    sb = new StringBuilder("</");
    sb.append(etiqueta).append(">");
    int posEtiquetaCierre = documento.indexOf(sb.toString());
    return documento.substring(posEtiquetaApertura + etiqueta.length() + 2, posEtiquetaCierre);
}

From source file:Main.java

public static String passwordEncoder(String params) {
    StringBuilder param = new StringBuilder(params);
    param.append("&@*#^%^%$&");
    char[] md5 = md5Encoder(param.toString(), false).toCharArray();
    if (md5.length == 32) {
        param.append(md5[5]).append(md5[1]).append(md5[11]).append(md5[8]).append(md5[18]).append(md5[30])
                .append(md5[28]).append(md5[22]);
    }/* w ww  .  ja  v  a2  s.c  om*/
    return md5Encoder(param.toString(), false);
}

From source file:Main.java

public static String getCompressedNumberString(int num) {
    DecimalFormat df = new DecimalFormat("0.0");
    double tg = num;
    int si = 0;//from   w w w.ja  va 2s.  c o  m
    while (tg > 1000) {
        tg /= 1000.0;
        si++;
    }
    if ((int) tg == num) {
        df = new DecimalFormat("0");
    } else {
        df = new DecimalFormat("0.0");
    }
    StringBuilder sb = new StringBuilder();
    sb.append(df.format(tg));
    sb.append(numberSuffixes[si]);
    return sb.toString();
}

From source file:Main.java

static String removeNamespace(String xml) {
    int start = xml.indexOf(" xmlns=\"");
    int end = xml.indexOf('"', start + "xmlns=\"".length() + 1);
    if (start != -1) {
        StringBuilder sb = new StringBuilder(xml.substring(0, start));
        sb.append(xml.substring(end + 1));
        return sb.toString();
    }//  w w w.  j  a va 2  s  . co  m
    return xml;
}

From source file:Main.java

public static String toString(Collection coll, String sep) {
    if (coll == null)
        return null;
    StringBuilder sbuf = new StringBuilder(sep == "\n" ? sep : "");
    for (Object o : coll)
        sbuf.append("" + o + sep);
    return sbuf.toString();
}

From source file:StringBuilderTester.java

public static String appendItems(List list) {
    StringBuilder b = new StringBuilder();

    for (Iterator i = list.iterator(); i.hasNext();) {
        b.append(i.next()).append(" ");
    }//w ww .  j a  v  a2 s. c  o  m

    return b.toString();
}

From source file:Main.java

public static String toString(Collection<? extends Object> collection, String separator) {
    StringBuilder sb = new StringBuilder();
    for (Object obj : collection) {
        sb.append(obj).append(separator);
    }/*from   w  w w . j a va 2  s. c  o m*/
    return sb.toString();
}

From source file:Main.java

public static String convertIntArrayToString(int[] ran, String split) {
    StringBuilder s = new StringBuilder();
    for (int n = 0; n < ran.length; n++) {
        s.append(ran[n] + split);/*w w w . j  a v a2s  .  com*/
    }

    return s.toString();
}

From source file:Main.java

public static String convertPhoneNumberTo8Format(String text) {
    try {/*from   ww  w  . ja  v  a 2 s  .c  o  m*/
        text = text.trim();
        if (text.charAt(0) == '+') {
            text = text.substring(1);
        }
        if (text.charAt(0) == '7') {
            StringBuilder strBuilder = new StringBuilder(text);
            strBuilder.setCharAt(0, '8');
            text = strBuilder.toString();
        }
        BigInteger dummy = new BigInteger(text);
        if (text.charAt(0) != '8' || text.length() != 11) {
            throw new Exception();
        }
    } catch (Throwable t) {
        text = "";
        //LOGE("convertPhoneNumberTo8Format: " + t.getMessage());
        t.printStackTrace();
    }

    return text;
}