Example usage for java.lang StringBuilder deleteCharAt

List of usage examples for java.lang StringBuilder deleteCharAt

Introduction

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

Prototype

@Override
public StringBuilder deleteCharAt(int index) 

Source Link

Usage

From source file:Main.java

public static String getTags(List<String> tags, String block) {
    int tagSize = tags.size();
    StringBuilder result = new StringBuilder();
    for (int i = 0; i < tagSize; i++) {
        result.append(tags.get(i) + block);
    }/*  w w  w .  j a v  a 2  s .  com*/
    result.deleteCharAt(result.lastIndexOf(block));
    return result.toString();
}

From source file:Main.java

public static <T> String join(T[] array, String join) {
    StringBuilder builder = new StringBuilder();
    for (T t : array) {
        builder.append(t);/*from w  ww .  j  a  v  a 2s. c  om*/
        builder.append(join);
    }
    return builder.deleteCharAt(builder.length() - 1).toString();
}

From source file:Main.java

public static void setOptionsPostStr(Map<String, String> ret, String optionName, boolean[] flags) {
    StringBuilder buf = new StringBuilder();
    for (int i = 0; i < flags.length; i++) {
        if (flags[i])
            buf.append("," + i);
    }//w w w  .j a va  2s  .c  o  m
    buf.deleteCharAt(0);
    ret.put(optionName, buf.toString());
}

From source file:Main.java

/**
 * Trim leading and trailing whitespace from the given String.
 * @param str the String to check/*from   w  w  w. ja  v a 2s  .c  om*/
 * @return the trimmed String
 * @see java.lang.Character#isWhitespace
 */
public static String trimWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder(str);
    while (sb.length() > 0 && Character.isWhitespace(sb.charAt(0))) {
        sb.deleteCharAt(0);
    }
    while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:Main.java

public static String bytesToHex(byte[] data, int offset, int length) {
    if (length <= 0) {
        return "";
    }/*from  ww  w .j a v  a  2 s  .c o m*/

    StringBuilder hex = new StringBuilder();
    for (int i = offset; i < offset + length; i++) {
        hex.append(String.format(" %02X", data[i] % 0xFF));
    }
    hex.deleteCharAt(0);
    return hex.toString();
}

From source file:Main.java

/**
 * Trim all occurrences of the supplied trailing character from the given String.
 * @param str the String to check//from  w  ww .j a va 2s . co m
 * @param trailingCharacter the trailing character to be trimmed
 * @return the trimmed String
 */
public static String trimTrailingCharacter(String str, char trailingCharacter) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder(str);
    while (sb.length() > 0 && sb.charAt(sb.length() - 1) == trailingCharacter) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * buildStringFromArray/*from w w  w.j a  va  2 s .  c  o  m*/
 *
 * @param stringArray the String[] to convert
 * @param separator   the string separator
 * @return the separated string
 */
public static String buildStringFromArray(ArrayList<String> stringArray, String separator) {
    if (stringArray.size() > 0) {
        StringBuilder nameBuilder = new StringBuilder();
        for (String n : stringArray) {
            nameBuilder.append(n).append(separator);
        }
        nameBuilder.deleteCharAt(nameBuilder.length() - 1);
        return nameBuilder.toString();
    } else {
        return null;
    }
}

From source file:Main.java

/**
 * Trim trailing whitespace from the given String.
 * @param str the String to check//from  ww  w  . ja  v a 2 s  .  com
 * @return the trimmed String
 * @see java.lang.Character#isWhitespace
 */
public static String trimTrailingWhitespace(String str) {
    if (!hasLength(str)) {
        return str;
    }
    StringBuilder sb = new StringBuilder(str);
    while (sb.length() > 0 && Character.isWhitespace(sb.charAt(sb.length() - 1))) {
        sb.deleteCharAt(sb.length() - 1);
    }
    return sb.toString();
}

From source file:Main.java

/**
 * merge the refer variable by target mainRefer and otherRefer, refer variable is something like: 'user,handler''
 * @param mainRefer the main refer variable
 * @param otherRefer the other refer variable
 * @return the new he refer variable// w  w  w .j a v a 2 s  .c om
 */
public static String mergeReferVariable(String mainRefer, String otherRefer) {
    if (mainRefer == null)
        return otherRefer;
    if (otherRefer == null)
        return mainRefer;
    if (mainRefer.equals(otherRefer))
        return mainRefer;

    final String[] mainStrs = mainRefer.split(",");
    final String[] otherStrs = otherRefer.split(",");

    for (int i = 0, size = mainStrs.length; i < size; i++) {
        sSet.add(mainStrs[i]);
    }
    for (int i = 0, size = otherStrs.length; i < size; i++) {
        sSet.add(otherStrs[i]);
    }
    StringBuilder sb = new StringBuilder();
    for (String str : sSet) {
        sb.append(str).append(",");
    }
    //delete last
    sb.deleteCharAt(sb.length() - 1);
    sSet.clear();
    return sb.toString();
}

From source file:Main.java

public static String intArrayToString(int[] ia) {
    if (ia == null) {
        return "";
    }/*from  w w w .j  a v  a 2s. co  m*/
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < ia.length; i++) {
        sb.append(';');
        sb.append(ia[i]);
    }
    if (ia.length > 0) {
        sb.deleteCharAt(0);
    }
    return sb.toString();
}