StringBuffer: setLength(int length) : StringBuffer « java.lang « Java by API Java by API java.lang StringBuffer StringBuffer: setLength(int length)
/*
* Output:
buffer before = Hello
charAt(1) before = e
buffer after = He
charAt(1) after = e
* */
public class MainClass {
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.setLength(2);
System.out.println("buffer after = " + sb);
System.out.println("charAt(1) after = " + sb.charAt(1));
}
}
Related examples in the same category 1. new StringBuffer(int size) 2. new StringBuffer(String str) 3. StringBuffer: append(char c) 4. StringBuffer: append(char[] str, int offset, int len) 5. StringBuffer: append(CharSequence s, int start, int end) 6. StringBuffer: append(double d) 7. StringBuffer: append(float f) 8. StringBuffer: append(int intValue) 9. StringBuffer: append(long lng) 10. StringBuffer: append(String stringValue) 11. StringBuffer: capacity 12. StringBuffer: charAt(int index) 13. StringBuffer: delete(int start, int end) 14. StringBuffer: deleteCharAt(int pos) 15. StringBuffer: getChars(int srcBegin, int srcEnd, char[] dst, int dstBegin) 16. StringBuffer: insert(int offset, boolean b) 17. StringBuffer: insert(int offset, char c) 18. StringBuffer: insert(int offset, char[] str) 19. StringBuffer: insert(int offset, double d) 20. StringBuffer: insert(int offset, float f) 21. StringBuffer: insert(int offset, int i) 22. StringBuffer: insert(int offset, long l) 23. StringBuffer: insert(int offset, Object obj) 24. StringBuffer: insert(int offset, String stringValue) 25. StringBuffer: lastIndexOf(String str) 26. StringBuffer: length() 27. StringBuffer: replace(int start, int end, String str) 28. StringBuffer: reverse() 29. StringBuffer: setCharAt(int index) 30. StringBuffer: toString()