Java — Important Methods of StringBuffer Class | Code Factory

StringBuffer sb = new StringBuffer("Code");
System.out.println(sb.length()); // 4
StringBuffer sb = new StringBuffer("Code");
System.out.println(sb.capacity()); // 20
StringBuffer sb = new StringBuffer("Code");
System.out.println(sb.charAt(0)); // C
System.out.println(sb.charAt(5)); // RE : java.lang.StringIndexOutOfBoundsException: String index out of range: 5
StringBuffer sb = new StringBuffer("Code");
sb.setCharAt(3, 'o');
System.out.println(sb); // Codo
1. public StringBuffer append(boolean b)
2. public StringBuffer append(char c)
3. public StringBuffer append(char[] str)
4. public StringBuffer append(char[] str, int offset, int len)
5. public StringBuffer append(CharSequence s)
6. public StringBuffer append(CharSequence s, int start, int end)
7. public StringBuffer append(double d)
8. public StringBuffer append(float f)
9. public StringBuffer append(int i)
10. public StringBuffer append(long lng)
11. public StringBuffer append(Object obj)
12. public StringBuffer append(String str)
13. public StringBuffer append(StringBuffer sb)
StringBuffer sb = new StringBuffer("Code");
System.out.println(sb); // Code123
1. public StringBuffer insert(int offset, boolean b)
2. public StringBuffer insert(int offset, char c)
3. public StringBuffer insert(int offset, char[] str)
4. public StringBuffer insert(int index, char[] str, int offset, int len)
5. public StringBuffer insert(int dstOffset, CharSequence s)
6. public StringBuffer insert(int dstOffset, CharSequence s, int start, int end)
7. public StringBuffer insert(int offset, double d)
8. public StringBuffer insert(int offset, float f)
9. public StringBuffer insert(int offset, int i)
10. public StringBuffer insert(int offset, long l)
11. public StringBuffer insert(int offset, Object obj)
12. public StringBuffer insert(int offset, String str)
StringBuffer sb = new StringBuffer("Code");
sb.insert(0, 123);
System.out.println(sb); // 123Code
StringBuffer sb = new StringBuffer("Code");
sb.delete(3, 4);
System.out.println(sb); // Cod
StringBuffer sb = new StringBuffer("Code");
System.out.println(sb); // Cod
StringBuffer sb = new StringBuffer("Code");
System.out.println(sb.reverse()); // edoC
StringBuffer sb = new StringBuffer("CodeFactory");
System.out.println(sb); // Code
StringBuffer sb = new StringBuffer();
System.out.println(sb.capacity()); // 16
System.out.println(sb.capacity()); // 50
StringBuffer sb = new StringBuffer(50);
System.out.println(sb.capacity()); // 50
System.out.println(sb.capacity()); // 4




Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

GoFrarme 101: Add ratelimit middleware

Convert *.mkv to *.mp3 with ffmpeg

Write LOT numbers

Accident Lawyer Sandy Utah

accident lawyer sandy utah

READ/DOWNLOAD$( RCM — Gateway to World Class Mainte

Adding a health powerup in Unity

RESTful API with CakePHP (2.9)

Overcome Life Challenges While Learning How to Code

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Code Factory

Code Factory

More from Medium

What is Code Review and the Key Tips and Tricks

Spending Time Keeping Your Code Clean Is Not Just Cost Effective; It Is a Matter of Professional…

Does good code take longer to write than bad code?

60 Day Milestone!

We are gonna get there.

Why do we need Unicode?