Example usage for java.lang StringBuffer StringBuffer

List of usage examples for java.lang StringBuffer StringBuffer

Introduction

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

Prototype

public StringBuffer(CharSequence seq) 

Source Link

Document

Constructs a string buffer that contains the same characters as the specified CharSequence .

Usage

From source file:Main.java

public static void main(String args[]) {
    Set set = new HashSet();
    Set set2 = new HashSet();
    StringBuffer buff1 = new StringBuffer("Irish Setter");
    StringBuffer buff2 = new StringBuffer("Irish Setter");
    set.add(buff1);//w ww  .  j  a  v  a 2 s  . co m
    set2.add(buff2);
    System.out.println(set.addAll(set2));
    System.out.println(set.addAll(set));
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("Hello");
    System.out.println("buffer before = " + sb);
    System.out.println("charAt(1) before = " + sb.charAt(1));
    sb.setCharAt(1, 'i');
    System.out.println("buffer after = " + sb);
    System.out.println("charAt(1) after = " + sb.charAt(1));

}

From source file:TransformerExampleV1.java

public static void main(String args[]) {
    Transformer transformer = TransformerUtils.invokerTransformer("append", new Class[] { String.class },
            new Object[] { " a Transformer?" });
    Object newObject = transformer.transform(new StringBuffer("Are you"));
    System.err.println(newObject);
}

From source file:ReverseConsoleInput.java

public static void main(String args[]) throws Exception {
    InputStreamReader isr = new InputStreamReader(System.in);
    BufferedReader br = new BufferedReader(isr);

    // Read and process lines from console
    String s;//www. j ava2  s .c om
    while ((s = br.readLine()) != null) {
        StringBuffer sb = new StringBuffer(s);
        sb.reverse();
        System.out.println(sb);
    }
    isr.close();
}

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);//from w  ww .  j ava2 s  .  co m
    // 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:StringIOApp.java

public static void main(String args[]) throws IOException {
    StringWriter outStream = new StringWriter();
    String s = "This is a test.";
    for (int i = 0; i < s.length(); ++i)
        outStream.write(s.charAt(i));/*from w ww  .j  ava 2s . com*/
    System.out.println("outstream: " + outStream);
    System.out.println("size: " + outStream.toString().length());
    StringReader inStream;
    inStream = new StringReader(outStream.toString());
    int ch = 0;
    StringBuffer sb = new StringBuffer("");
    while ((ch = inStream.read()) != -1)
        sb.append((char) ch);
    s = sb.toString();
    System.out.println(s.length() + " characters were read");
    System.out.println("They are: " + s);
}

From source file:Main.java

public static void main(String args[]) throws IOException {
    CharArrayWriter outStream = new CharArrayWriter();
    String s = "This is a test.";
    for (int i = 0; i < s.length(); ++i)
        outStream.write(s.charAt(i));/*w ww . ja  v  a2  s.c  o  m*/
    System.out.println("outstream: " + outStream);
    System.out.println("size: " + outStream.size());
    CharArrayReader inStream;
    inStream = new CharArrayReader(outStream.toCharArray());
    int ch = 0;
    StringBuffer sb = new StringBuffer("");
    while ((ch = inStream.read()) != -1)
        sb.append((char) ch);
    s = sb.toString();
    System.out.println(s.length() + " characters were read");
    System.out.println("They are: " + s);
}

From source file:MainClass.java

public static void main(String[] args) throws Exception {
    Document document = new Document(PageSize.A4);
    PdfWriter writer = PdfWriter.getInstance(document, new FileOutputStream("2.pdf"));
    document.open();//  ww w.  j a v  a2s  . c o m
    PdfContentByte cb = writer.getDirectContent();
    StringBuffer sb = new StringBuffer(1024);
    BufferedReader reader = new BufferedReader(new FileReader("a.txt"));
    int c;
    while ((c = reader.read()) > -1) {
        sb.append((char) c);
    }
    reader.close();
    ColumnText ct = new ColumnText(cb);
    ct.setSimpleColumn(new Phrase(sb.toString()), 36, 36, PageSize.A4.width() - 36, PageSize.A4.height() - 36,
            18, Element.ALIGN_JUSTIFIED);
    int status = ColumnText.START_COLUMN;
    while (ColumnText.hasMoreText(status)) {
        status = ct.go();
        ct.setYLine(PageSize.A4.height() - 36);
        document.newPage();
    }
    document.close();
}

From source file:FileDialogMultipleFileNameSelection.java

public static void main(String[] args) {
    Display display = new Display();
    final Shell shell = new Shell(display);

    FileDialog dlg = new FileDialog(shell, SWT.MULTI);
    Collection files = new ArrayList();
    if (dlg.open() != null) {
        String[] names = dlg.getFileNames();
        for (int i = 0, n = names.length; i < n; i++) {
            StringBuffer buf = new StringBuffer(dlg.getFilterPath());
            if (buf.charAt(buf.length() - 1) != File.separatorChar)
                buf.append(File.separatorChar);
            buf.append(names[i]);/*ww  w . ja  v  a  2  s .com*/
            files.add(buf.toString());
        }
    }
    System.out.println(files);
    display.dispose();

}

From source file:CreateTableWithAllDataTypesInMySQL.java

public static void main(String[] args) throws Exception {
    PreparedStatement pstmt = null;
    Connection conn = null;/* ww  w. j  ava  2 s  . c o m*/
    try {
        StringBuffer sql = new StringBuffer("CREATE TABLE tableWithAllTypes(");
        sql.append("column_boolean       BOOL, "); // boolean
        sql.append("column_byte          TINYINT, "); // byte
        sql.append("column_short         SMALLINT, "); // short
        sql.append("column_int           INTEGER, "); // int
        sql.append("column_long          BIGINT, "); // long
        sql.append("column_float         FLOAT, "); // float
        sql.append("column_double        DOUBLE PRECISION, "); // double
        sql.append("column_bigdecimal    DECIMAL(13,0), "); // BigDecimal
        sql.append("column_string        VARCHAR(254), "); // String
        sql.append("column_date          DATE, "); // Date
        sql.append("column_time          TIME, "); // Time
        sql.append("column_timestamp     TIMESTAMP, "); // Timestamp
        sql.append("column_asciistream1  TINYTEXT, "); // Clob ( 2^8 bytes)
        sql.append("column_asciistream2  TEXT, "); // Clob ( 2^16 bytes)
        sql.append("column_asciistream3  MEDIUMTEXT, "); // Clob (2^24 bytes)
        sql.append("column_asciistream4  LONGTEXT, "); // Clob ( 2^32 bytes)
        sql.append("column_blob1         TINYBLOB, "); // Blob ( 2^8 bytes)
        sql.append("column_blob2         BLOB, "); // Blob ( 2^16 bytes)
        sql.append("column_blob3         MEDIUMBLOB, "); // Blob ( 2^24 bytes)
        sql.append("column_blob4         LONGBLOB)"); // Blob ( 2^32 bytes)

        conn = getConnection();
        pstmt = conn.prepareStatement(sql.toString());
        pstmt.executeUpdate();
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        conn.close();
    }
}