Return | Method | Summary |
---|---|---|
char | charAt(int index) | Returns the char value in this sequence at the specified index. |
void | setCharAt(int index, char ch) | The character at the specified index is set to ch. |
void | getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) | Characters are copied from this sequence into the destination character array dst. |
int | indexOf(String str) | Returns the index within this string of the first occurrence of the specified substring. |
int | indexOf(String str, int fromIndex) | Returns the index within this string of the first occurrence of the specified substring, starting at the specified index. |
int | lastIndexOf(String str) | Returns the index within this string of the rightmost occurrence of the specified substring. |
int | lastIndexOf(String str, int fromIndex) | Returns the index within this string of the last occurrence of the specified substring. |
public class Main {
public static void main(String[] argv) {
StringBuffer sb = new StringBuffer();
sb.append("java2s.com");
char ch = sb.charAt(0);
System.out.println(ch);
}
}
The output:
j
The following example demonstrates charAt( ) and setCharAt( ):
public class Main {
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');
sb.setLength(2);
System.out.println("buffer after = " + sb);
System.out.println("charAt(1) after = " + sb.charAt(1));
}
}
The output:
buffer before = java2s.com
charAt(1) before = a
buffer after = ji
charAt(1) after = i
java2s.com | Contact Us | Privacy Policy |
Copyright 2009 - 12 Demo Source and Support. All rights reserved. |
All other trademarks are property of their respective owners. |