Comprehensive Guide to StringBuffer Class in Java
Learn the concepts of StringBuffer class covering functions like append, insert, reverse, and more. Prepared by Mahmoud Rafeek Alfarra.
Comprehensive Guide to StringBuffer Class in Java
E N D
Presentation Transcript
MINISTRY OF EDUCATION & HIGHER EDUCATION COLLEGE OF SCIENCE AND TECHNOLOGY (CST) KHANYOUNIS- PALESTINE Computer Programming 2 Lecture 6: String Processing Part c: Class StringBuffer Prepared & Presented by: Mahmoud Rafeek Alfarra
و من يتقِ الله ... ألا تكفيك هذه ؟! (إِنَّ اللَّهَ مَعَ الَّذِينَ اتَّقَوْا وَالَّذِينَ هُمْ مُحْسِنُونَ) (النحل:128) شريحـة ثابتـة لعلنا نحسن من خلالها أخلاقنـا و أفعالنا لنفوز يوم الامتحان الحقيقي Downloaded from http://staff.cst.ps/mfarra
Out Lines • What is a StringBuffer class ? • Functions of StringBuffer Class: • append() • insert() • reverse() • setCharAt() • charAt() • substring() • deleteCharAt() • length() • delete() • capacity() • setLength() • ensureCapacity() • toString() Downloaded from http://staff.cst.ps/mfarra
What is a StringBuffer class ? • A Stringbuffer class implements a mutable sequence of characters. • A string buffer is like a String, but can be modified. • At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. Downloaded from http://staff.cst.ps/mfarra
Functions of StringBuffer Class • append(): is used for the concatenate the string in string buffer. • This is better to use for dynamic string concatenation. • This function works like a simple string concatenation such as : String str = str + "added string";. Downloaded from http://staff.cst.ps/mfarra
String in Java • insert() • This is the insert() function used to insert any string or character at the specified position in the given string. StringBuffer buffer = new StringBuffer(“MFarra”); buffer.insert( 1, “R” ); Downloaded from http://staff.cst.ps/mfarra
Class String • reverse(): used to reverse the string present in string buffer. • setLength(int newLength)Sets the length of this String buffer. • capacity()Returns the current capacity of the String buffer. Downloaded from http://staff.cst.ps/mfarra
Case Study Return to chapter 29, and understand the remainder of functions Downloaded from http://staff.cst.ps/mfarra
Next Lecture … Class Regular Expressions Downloaded from http://staff.cst.ps/mfarra