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:MainClass.java

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

    System.out.println("sb = " + sb);
    System.out.println("Length = " + sb.length());
    System.out.println("Capacity = " + sb.capacity());

    sb.setLength(2);/*from ww  w  .j a  v  a  2  s  . c om*/

    System.out.println("sb = " + sb);
    System.out.println("Length = " + sb.length());
    System.out.println("Capacity = " + sb.capacity());

    sb.setLength(4);

    System.out.println("sb = " + sb);
    System.out.println("Length = " + sb.length());
    System.out.println("Capacity = " + sb.capacity());
}

From source file:MainClass.java

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

    System.out.println(phrase.charAt(5));

    char[] textArray = new char[3];
    phrase.getChars(9, 12, textArray, 0);

    for (char ch : textArray) {
        System.out.println(ch);/* w w w  . j a v a  2s.c  o m*/

    }
}

From source file:MainClass.java

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

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

    newString.setLength(8);/*w  w  w  .ja  v a 2 s .  c o  m*/

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

}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer(40);
    sb.append(5);
    System.out.println(sb);
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer(40);
    sb.append(5);//  w  w  w .jav a2s  .com
    String s = sb.toString();
    System.out.println(s);
}

From source file:MainClass.java

public static void main(String args[]) {
    StringBuffer buffer = new StringBuffer("hello there");

    System.out.printf("buffer = %s\n", buffer.toString());
    System.out.printf("Character at 0: %s\nCharacter at 4: %s\n\n", buffer.charAt(0), buffer.charAt(4));

    char charArray[] = new char[buffer.length()];
    buffer.getChars(0, buffer.length(), charArray, 0);
    System.out.print("The characters are: ");

    for (char character : charArray)
        System.out.print(character);

    buffer.setCharAt(0, 'H');
    buffer.setCharAt(6, 'T');
    System.out.printf("\n\nbuf = %s", buffer.toString());

    buffer.reverse();/*from  w  ww  . j a  v a 2  s.  c  o  m*/
    System.out.printf("\n\nbuf = %s\n", buffer.toString());
}

From source file:Main.java

public static void main(String[] args) {
    String words = "Morning";

    String reverse = new StringBuffer(words).reverse().toString();

    System.out.println("Normal : " + words);
    System.out.println("Reverse: " + reverse);
}

From source file:Main.java

public static void main(String[] arg) {

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

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

From source file:Main.java

public static void main(String[] argv) throws Exception {
    String s1 = "s1";

    StringBuffer sbuf = new StringBuffer("a");
    boolean b = s1.contentEquals(sbuf);
}

From source file:MainClass.java

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