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 void main(String[] argv) {
    StringBuilder sb = new StringBuilder();
    sb.append("java2s.com");

    System.out.println(sb.length());
    System.out.println(sb.capacity());

    sb.trimToSize();/*from  ww  w.  jav  a  2 s . c  o  m*/

    System.out.println(sb.length());
    System.out.println(sb.capacity());

}

From source file:Main.java

public static void main(String[] arg) {

    StringBuilder buffer = new StringBuilder("from java2s.com");

    buffer.append(buffer);

    System.out.println(buffer);/* w w  w  .j  a v a  2 s.c o m*/
}

From source file:Main.java

public static void main(String[] args) {
    StringBuilder sb = new StringBuilder(200); // Capacity:200, length:0
    sb.append("Hello"); // Capacity:200, length:5
    int len = sb.length(); // len is assigned 5
    int capacity = sb.capacity(); // capacity is assigned 200

}

From source file:Main.java

public static void main(String args[]) {

    // create an empty array list
    ArrayList<StringBuilder> arrlist1 = new ArrayList<StringBuilder>();

    // use add for new value
    arrlist1.add(new StringBuilder("from java2s.com"));

    // using clone to affect the objects pointed to by the references.
    ArrayList arrlist2 = (ArrayList) arrlist1.clone();

    // appending the string
    StringBuilder strbuilder = arrlist1.get(0);
    strbuilder.append("tutorials");

    System.out.println(arrlist1);

    System.out.println(arrlist2);
}

From source file:Main.java

public static void main(String[] a) {
    StringBuilder builder = new StringBuilder("Line 1\n");

    builder.append("Line 3\n");

    String lineToInsert = "Line 2\n";

    builder.insert(0, lineToInsert);//from w  w  w  .  ja  va 2s .  c  om

    System.out.println(builder.toString());

}

From source file:Main.java

public static void main(String[] args) {
    final StringBuilder sb = new StringBuilder();
    sb.append("<html>");
    sb.append("<body><ol>");
    Font[] fonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
    for (Font font : fonts) {
        String name = font.getName();
        sb.append("<li style='font-family: " + name + "; font-size: 20px;'>");
        sb.append(name);/*from  w  w  w.j a v a  2 s  . c om*/
    }

    JScrollPane sp = new JScrollPane(new JLabel(sb.toString()));
    Dimension d = sp.getPreferredSize();
    sp.setPreferredSize(new Dimension(d.width, 150));
    JOptionPane.showMessageDialog(null, sp);
}

From source file:Main.java

public static void main(String[] arg) {

    StringBuilder buffer = new StringBuilder();

    int i = 123;//from   ww w  . ja v  a  2  s . c o m
    buffer.append(i);

    System.out.println(buffer);
}

From source file:Main.java

public static void main(String[] arg) {

    StringBuilder buffer = new StringBuilder();
    float f = 123.45F;
    buffer.append(f);
    System.out.println(buffer);/*w ww. j a v  a  2 s .com*/
}

From source file:Main.java

public static void main(String args[]) {
    StringBuilder sb = new StringBuilder();
    sb.ensureCapacity(100);/* w  w w . j  av a 2  s .co m*/
    sb.append("java2s.com");
    System.out.println(sb.capacity());
    System.out.println(sb.length());
    System.out.println(sb.toString());

}

From source file:Main.java

public static void main(String[] a) {
    StringBuilder builder = new StringBuilder("Line 1\n");

    builder.append("Line 3\n");

    builder.insert(0, "Line 2\n");

    System.out.println(builder.toString());

    builder = builder.delete(2, 6);/*ww w.j av  a 2s  .c  o  m*/

    System.out.println(builder.toString());

}