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[] arg) {

    CharSequence phrase = "abced";
    StringBuffer buffer = new StringBuffer(phrase);

    System.out.println(buffer);/*from   w w w .jav  a2s. co m*/
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("Hello");
    System.out.println("capacity = " + sb.capacity());
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("hello world!");
    sb.insert(6, "there ");
    System.out.println(sb);//w w  w .  j  a va2  s  . co  m
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer(40);
    System.out.println(sb);/* www .  j  a  va 2 s .c  o m*/
    System.out.println("Length: " + sb.length());
    System.out.println("Capacity:" + sb.capacity());
}

From source file:MainClass.java

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

    sb.replace(5, 7, "was");
    System.out.println("After replace: " + sb);
}

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));
}

From source file:Main.java

public static void main(String[] args) {

    String str1 = "java2s.com";
    String str2 = "java2s.com";

    StringBuffer strbuf = new StringBuffer(str1);
    System.out.println("Method returns : " + str2.contentEquals(strbuf));

    str2 = str1.toUpperCase();//ww w  .  j  a  v  a  2s.com
    System.out.println("Method returns : " + str2.contentEquals(strbuf));
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb1 = new StringBuffer("abcde");
    sb1.append("abcdefghij");
    StringBuffer sb2 = sb1.reverse();
    System.out.println(sb1);//from w  w  w. j a  v a  2 s  .com
    System.out.println(sb2);
}

From source file:MainClass.java

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

    sb.delete(4, 7);/*from   w  w  w.  j av  a  2  s. c o 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) {
    boolean b = true;
    StringBuffer sb1 = new StringBuffer("1234567890");
    sb1.insert(6, b);/*from  w w  w . ja v a2s .c o  m*/
    System.out.println(sb1);

    char c = 'Y';
    sb1.insert(6, c);
    System.out.println(sb1);

    char[] c1 = new char[] { 'Y', 'e', 's' };
    sb1.insert(6, c1);
    System.out.println(sb1);

    double d = 1.0;
    sb1.insert(6, d);
    System.out.println(sb1);

    float f = 2.0f;
    sb1.insert(6, f);
    System.out.println(sb1);

    int i = 5;
    sb1.insert(6, i);
    System.out.println(sb1);

    long l = 10;
    sb1.insert(6, l);
    System.out.println(sb1);

    Object obj = new String("b");
    sb1.insert(6, obj);
    System.out.println(sb1);

    String str = "a";
    sb1.insert(6, str);
    System.out.println(sb1);
}