Example usage for java.lang StringBuffer deleteCharAt

List of usage examples for java.lang StringBuffer deleteCharAt

Introduction

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

Prototype

@Override
public synchronized StringBuffer deleteCharAt(int index) 

Source Link

Usage

From source file:Main.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("java2s.com.");

    sb.deleteCharAt(0);
    System.out.println("After deleteCharAt: " + sb);
}

From source file:MainClass.java

public static void main(String[] arg) {
    StringBuffer phrase = new StringBuffer("one two three four");

    phrase.deleteCharAt(10);

    System.out.println(phrase);//w w w  .  j  a  v a2  s.c o  m

}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("This is a test.");

    sb.delete(4, 7);/*w  w  w .  ja  v a2s .co m*/
    System.out.println("After delete: " + sb);

    sb.deleteCharAt(0);
    System.out.println("After deleteCharAt: " + sb);
}

From source file:Main.java

public static void main(String[] args) {
    StringBuffer sb1 = new StringBuffer("Hello World");
    sb1.delete(0, 6);/*from ww  w.ja  v a  2 s .  c  o m*/

    System.out.println(sb1);
    sb1.delete(0, sb1.length());
    System.out.println(sb1);

    sb1 = new StringBuffer("Hello World");
    sb1.deleteCharAt(0);
    System.out.println(sb1);
}

From source file:MainClass.java

public static void main(String args[]) {
    Object objectRef = "hello";
    String string = "goodbye";
    char charArray[] = { 'a', 'b', 'c', 'd', 'e', 'f' };
    boolean booleanValue = true;
    char characterValue = 'K';
    int integerValue = 7;
    long longValue = 10000000;
    float floatValue = 2.5f;
    double doubleValue = 33.3;

    StringBuffer buffer = new StringBuffer();

    buffer.insert(0, objectRef);/* w w  w . j  a  va  2  s. co  m*/
    buffer.insert(0, "  ");
    buffer.insert(0, string);
    buffer.insert(0, "  ");
    buffer.insert(0, charArray);
    buffer.insert(0, "  ");
    buffer.insert(0, charArray, 3, 3);
    buffer.insert(0, "  ");
    buffer.insert(0, booleanValue);
    buffer.insert(0, "  ");
    buffer.insert(0, characterValue);
    buffer.insert(0, "  ");
    buffer.insert(0, integerValue);
    buffer.insert(0, "  ");
    buffer.insert(0, longValue);
    buffer.insert(0, "  ");
    buffer.insert(0, floatValue);
    buffer.insert(0, "  ");
    buffer.insert(0, doubleValue);

    System.out.printf("buffer after inserts:\n%s\n\n", buffer.toString());

    buffer.deleteCharAt(10);
    buffer.delete(2, 6);

    System.out.printf("buffer after deletes:\n%s\n", buffer.toString());
}

From source file:Main.java

public static String trimTail(StringBuffer sb, char tail) {
    if (sb.length() > 0 && sb.charAt(sb.length() - 1) == tail)
        sb.deleteCharAt(sb.length() - 1);
    return sb.toString();
}

From source file:Main.java

/**
 * Convert the list of Integers into a comma separated
 * string so that it's easy to load back in.
 * @param list/*from   ww w .j  a  va 2s .c o m*/
 * @return
 */
public static String toString(List<?> list) {
    StringBuffer buf = new StringBuffer();
    for (Object o : list)
        buf.append(o + ",");
    buf.deleteCharAt(buf.length() - 1);
    return buf.toString();
}

From source file:gov.nyc.doitt.gis.geoclient.parser.regex.PatternUtils.java

public static String literalMatchGroup(Collection<String> strings) {
    Assert.notEmpty(strings, "Collection of strings argument cannot be empty or null");
    StringBuffer buff = new StringBuffer("(");
    for (String s : strings) {
        buff.append(s);//from  www  . j av a  2 s.  c  o  m
        buff.append("|");
    }
    buff.deleteCharAt(buff.lastIndexOf("|"));
    buff.append(")");
    return buff.toString();
}

From source file:Main.java

/**
 * returns a string where each object in the give {@code Collection} is placed on a new line
 * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz)
 * @param collection a given {@code Collection} of type {@code T}
 * @return/* w ww.  ja  v a 2s. com*/
 */
public static <T> String lineSeparatedCollection(Collection<T> collection) {
    StringBuffer sb = new StringBuffer("");
    for (T item : collection) {
        sb.append(item.toString()).append(LINE_SEPARATOR);
    }
    return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString();
}

From source file:Main.java

/**
 * returns a string where each object in the give {@code Collection} is placed on a new line
 * (i.e [foo, bar, bizz] -> <br/> foo <br/> bar <br/> bizz)
 * @param collection a given {@code Array} of type {@code T}
 * @return/*from   w  w w . ja  va  2 s  .  co m*/
 */
public static <T> String lineSeparatedCollection(T... collection) {
    StringBuffer sb = new StringBuffer("");
    for (T item : collection) {
        sb.append(item.toString()).append(LINE_SEPARATOR);
    }
    return sb.deleteCharAt(sb.lastIndexOf(LINE_SEPARATOR)).toString();
}