Example usage for java.lang StringBuffer charAt

List of usage examples for java.lang StringBuffer charAt

Introduction

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

Prototype

@Override
public synchronized char charAt(int index) 

Source Link

Usage

From source file:Main.java

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

    System.out.println(buffer.charAt(0));
    System.out.println(buffer.charAt(4));

}

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);//from   ww w  .  j av a  2  s.com

    }
}

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]);//from   w  ww .jav a  2  s. co  m
            files.add(buf.toString());
        }
    }
    System.out.println(files);
    display.dispose();

}

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:setCharAtDemo.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');
    sb.setLength(2);/*from   www. j  av  a2s. c  o m*/
    System.out.println("buffer after = " + sb);
    System.out.println("charAt(1) after = " + sb.charAt(1));
}

From source file:Main.java

public static void main(String args[]) {
    StringBuffer sb = new StringBuffer("java2s.com");
    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: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:Main.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: ");

}

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();//w ww.  j  av  a2  s .  co m
    System.out.printf("\n\nbuf = %s\n", buffer.toString());
}

From source file:UnicodeChars.java

public static void main(String[] argv) {
    //+//from  ww  w. java  2  s. com
    StringBuffer b = new StringBuffer();
    for (char c = 'a'; c < 'd'; c++) {
        b.append(c);
    }
    b.append('\u00a5'); // Japanese Yen symbol
    b.append('\u01FC'); // Roman AE with acute accent
    b.append('\u0391'); // GREEK Capital Alpha
    b.append('\u03A9'); // GREEK Capital Omega

    for (int i = 0; i < b.length(); i++) {
        System.out.println("Character #" + i + " is " + b.charAt(i));
    }
    System.out.println("Accumulated characters are " + b);
    //-
}