Example usage for java.lang StringBuffer append

List of usage examples for java.lang StringBuffer append

Introduction

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

Prototype

@Override
    public synchronized StringBuffer append(double d) 

Source Link

Usage

From source file:MainClass.java

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

    sb.append(true);

    sb.append('A');

    char[] carray = { 'a', 'b', 'c' };
    sb.append(carray);//from w  w w . j a  v  a  2 s  .  co m

    sb.append(carray, 0, 1);

    sb.append(3.5d);

    sb.append(2.4f);

    sb.append(45);

    sb.append(90000l);

    sb.append("That's all!");

    System.out.println(sb);
}

From source file:Main.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer();
    sb.ensureCapacity(100);/*from  w  w  w . ja  v a 2 s.c o  m*/
    sb.append("java2s.com");
    System.out.println(sb.capacity());
    System.out.println(sb.length());
    System.out.println(sb.toString());

}

From source file:ImmutableStrings.java

public static void main(String[] args) {
    String foo = "foo";
    String s = "abc" + foo + "def" + Integer.toString(47);
    System.out.println(s);/* w ww  .j a  v a  2 s  .  com*/
    // The "equivalent" using StringBuffer:
    StringBuffer sb = new StringBuffer("abc"); // Creates String!
    sb.append(foo);
    sb.append("def"); // Creates String!
    sb.append(Integer.toString(47));
    System.out.println(sb);

}

From source file:Main.java

public static void main(String[] arg) {

    StringBuffer buffer = new StringBuffer();

    long l = 123456789098765L;
    buffer.append(l);

    System.out.println(buffer);/*from w w  w .  j a va  2  s .  com*/
}

From source file:Main.java

public static void main(String[] arg) {

    StringBuffer buffer = new StringBuffer();
    CharSequence cs = "java2s.com";
    buffer.append(cs);
    System.out.println(buffer);/*w w w .  j a  va2s  .com*/
}

From source file:Main.java

public static void main(String[] arg) {

    StringBuffer buffer = new StringBuffer();

    Object o = "from java2s.com";
    buffer.append(o);

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

From source file:MainClass.java

public static void main(String[] arg) {
    StringBuffer buf = new StringBuffer("The number is ");
    long number = 999;
    buf.append(number);

    buf.append(12.34);/* ww  w .  j  a va  2 s . c o  m*/

    System.out.println(buf);
}

From source file:MainClass.java

public static void main(String[] arg) {
    StringBuffer newString = new StringBuffer("abcde1234567890");

    StringBuffer newBuffer = newString.append("saves nine");

    System.out.println(newBuffer);

}

From source file:Main.java

public static void main(String[] args) {
    boolean b = true;
    StringBuffer sb1 = new StringBuffer();
    sb1.append(b);
    System.out.println(sb1);//  w  w  w  .  ja v  a 2s  .  c o m

    char c = 'Y';
    sb1.append(c);
    System.out.println(sb1);

    char[] c1 = new char[] { 'Y', 'e', 's' };
    sb1.append(c1);

    System.out.println(sb1);

    double d = 1.0;
    sb1.append(d);
    System.out.println(sb1);

    float f = 1.0f;
    sb1.append(f);
    System.out.println(sb1);

    int i = 1;
    sb1.append(i);
    System.out.println(sb1);

    long l = 1;
    sb1.append(l);

    System.out.println(sb1);

    Object obj = new String("Yes");
    sb1.append(obj);
    System.out.println(sb1);

    String str = new String("Yes");
    sb1.append(str);
    System.out.println(sb1);
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    SSLServerSocketFactory ssf = (SSLServerSocketFactory) SSLServerSocketFactory.getDefault();
    ServerSocket ss = ssf.createServerSocket(8080);

    while (true) {
        try {/*  w  w w. java  2  s.c o m*/
            Socket s = ss.accept();
            OutputStream out = s.getOutputStream();
            BufferedReader in = new BufferedReader(new InputStreamReader(s.getInputStream()));

            String line = null;
            while (((line = in.readLine()) != null) && (!("".equals(line)))) {
                System.out.println(line);
            }
            StringBuffer buffer = new StringBuffer();
            buffer.append("<HTML><HEAD><TITLE>HTTPS Server</TITLE></HEAD>\n");
            buffer.append("<BODY>\n<H1>Success!</H1></BODY></HTML>\n");

            String string = buffer.toString();
            byte[] data = string.getBytes();
            out.write("HTTP/1.0 200 OK\n".getBytes());
            out.write(new String("Content-Length: " + data.length + "\n").getBytes());
            out.write("Content-Type: text/html\n\n".getBytes());
            out.write(data);
            out.flush();

            out.close();
            in.close();
            s.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}