SlideShare a Scribd company logo
BABA GHULAM SHAH BADSHAH UNIVERSITY (RAJOURI)
AJEELA MUSHTAQ
BABA GHULAM SHAH BADSHAH
UNIVERSITY- RAJOURI (J&K).
DEPARTMENT OF COMPUTER
SCIENCES
PRESENTATION TOPIC:-
PRESENTED BY:-
Ajeela Mushtaq Roll NO:-13-Mcs-15
PRESENTED To:-
MR MUZAFFAR AHMAD DAR
STRINGbuffer and stringbuilder
Strings
•
Strings, which are widely used in Java programming, are a sequence
of characters enquoted with double quotes
•
In Java programming language, strings are treated as objects.
•
The Java platform provides the String class to create and manipulate
strings.
Creating Strings
•
The most direct way to create a string is to write −
String str=“Hello world!”;
•
Whenever it encounters a string literal in your code, the compiler
creates a String object with its value in this case, "Hello world!'.
•
In java strings does not end with null character.
Java StringBuffer class
•
Java StringBuffer class is used to create mutable (modifiable) string.
•
The StringBuffer class in java is same as String class except it is
mutable i.e. it can be changed.
•
StringBuffer may have characters and substrings inserted in the
middle or appended to the end.
StringBuffer Constructors
•
StringBuffer defines these three constructors:
StringBuffer( )
StringBuffer(int size)
StringBuffer(String str)
•
The default constructor (the one with no parameters) reserves room
for 16 characters.
•
The second version accepts an integer argument that explicitly sets
the size of the buffer.
•
The third version accepts a String argument that sets the initial
contents of the StringBuffer object and reserves room for 16 more
Important methods of StringBuffer class
•
length( ) and capacity( )
•
The current length of a StringBuffer can be found via the length( )
method, while the total allocated capacity can be found through the
capacity( ) method.
•
They have the following general forms:
int length( )
int capacity( )
setLength( )
•
To set the length of the buffer within a StringBuffer object, use
setLength( ). Its general form is shown here:
void setLength(int len)
•
Here, len specifies the length of the buffer. This value must be
nonnegative.
charAt( ) and setCharAt( )
•
The value of a single character can be obtained from a StringBuffer
via the charAt( ) method.
•
You can set the value of a character within a StringBuffer using
setCharAt().
•
Their general forms are shown here:
char charAt(int where)
void setCharAt(int where, char ch)
•
For charAt( ), where specifies the index of the character being
obtained.
•
For setCharAt( ),where specifies the index of the character being set,
getChars( )
•
To copy a substring of a StringBuffer into an array, use the getChars( )
method.
•
It has this general form:
void getChars(int sourceStart, int sourceEnd, char target[ ],int targetStart)
•
Here, sourceStart specifies the index of the beginning of the
substring, and sourceEnd specifies an index that is one past the end of
the desired substring.
append( )
•
The append( ) method concatenates the string representation of any
other type of data to the end of the invoking StringBuffer object.
•
Syntax:
StringBuffer append(String str)
insert( )
•
The insert( ) method inserts one string into another. It is overloaded
to accept values of all the simple types, plus Strings, Objects, and
CharSequences.
•
This string is then inserted into the invoking StringBuffer object.
These are a few of its forms:
StringBuffer insert(int index, String str)
StringBuffer insert(int index, char ch)
StringBuffer insert(int index, Object obj)
•
Here, index specifies the index at which point the string will be
inserted into the invoking StringBuffer object.
reverse( )
•
You can reverse the characters within a StringBuffer object using
reverse( ), shown here:
StringBuffer reverse( )
•
This method returns the reversed object on which it was called.
substring( )
•
You can obtain a portion of a StringBuffer by calling substring( ). It
has the following two forms:
String substring(int startIndex)
String substring(int startIndex, int endIndex)
Java StringBuilder class
•
Java StringBuilder class is used to create mutable (modifiable) string.
•
The Java StringBuilder class is same as StringBuffer class except that it
is non-synchronized.
•
It is available since JDK 1.5.
Important Constructors of StringBuilder class
•
StringBuilder(): creates an empty string Builder with the initial
capacity of 16.
•
StringBuilder(String str): creates a string Builder with the specified
string.
•
StringBuilder(int length): creates an empty string Builder with the
specified capacity as length.
Method Description
public StringBuilder append() is used to append the specified string with this string.
public StringBuilder insert() is used to insert the specified string with this string at the specified position.
public StringBuilder replace(int startIndex, int endIndex, String str) is used to replace the string from specified startIndex and endIndex.
public StringBuilder delete(int startIndex, int endIndex) is used to delete the string from specified startIndex and endIndex.
public StringBuilder reverse() is used to reverse the string.
public int capacity() is used to return the current capacity.
public int length() is used to return the length of the string i.e. total number of characters.
public String substring(int beginIndex) is used to return the substring from the specified beginIndex.
public String substring(int beginIndex, int endIndex) is used to return the substring from the specified beginIndex and endIndex.
No. StringBuffer StringBuilder
1)
StringBuffer is synchronized i.e. thread safe. It
means two threads can't call the methods of
StringBuffer simultaneously.
StringBuilder is non-synchronized i.e. not
thread safe. It means two threads can call
the methods of StringBuilder
simultaneously.
2) StringBuffer is less efficient than StringBuilder.
StringBuilder is more efficient than
StringBuffer.
Thank you…!
Have a nice day
19

More Related Content

What's hot

Python strings
Python stringsPython strings
Python strings
Mohammed Sikander
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
Mohd Sajjad
 
Wrapper classes
Wrapper classes Wrapper classes
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)Ravi_Kant_Sahu
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
SIVASHANKARIRAJAN
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
Marcello Thiry
 
File in C language
File in C languageFile in C language
File in C language
Manash Kumar Mondal
 
Enums in c
Enums in cEnums in c
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
Nilesh Dalvi
 
Multi-threaded Programming in JAVA
Multi-threaded Programming in JAVAMulti-threaded Programming in JAVA
Multi-threaded Programming in JAVA
Vikram Kalyani
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
sambitmandal
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
Vishnu Suresh
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
Devashish Kumar
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
DrRajeshreeKhande
 

What's hot (20)

Python strings
Python stringsPython strings
Python strings
 
Python-02| Input, Output & Import
Python-02| Input, Output & ImportPython-02| Input, Output & Import
Python-02| Input, Output & Import
 
Java Strings
Java StringsJava Strings
Java Strings
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
 
String handling(string class)
String handling(string class)String handling(string class)
String handling(string class)
 
Constructor in java
Constructor in javaConstructor in java
Constructor in java
 
java.io - streams and files
java.io - streams and filesjava.io - streams and files
java.io - streams and files
 
File in C language
File in C languageFile in C language
File in C language
 
Enums in c
Enums in cEnums in c
Enums in c
 
9. Input Output in java
9. Input Output in java9. Input Output in java
9. Input Output in java
 
Multi-threaded Programming in JAVA
Multi-threaded Programming in JAVAMulti-threaded Programming in JAVA
Multi-threaded Programming in JAVA
 
Packages in java
Packages in javaPackages in java
Packages in java
 
Java I/O
Java I/OJava I/O
Java I/O
 
Java interface
Java interfaceJava interface
Java interface
 
Modules in Python Programming
Modules in Python ProgrammingModules in Python Programming
Modules in Python Programming
 
Packages,static,this keyword in java
Packages,static,this keyword in javaPackages,static,this keyword in java
Packages,static,this keyword in java
 
Data Structures in Python
Data Structures in PythonData Structures in Python
Data Structures in Python
 
Vectors in Java
Vectors in JavaVectors in Java
Vectors in Java
 
Interface in java
Interface in javaInterface in java
Interface in java
 
Dr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWTDr. Rajeshree Khande :Introduction to Java AWT
Dr. Rajeshree Khande :Introduction to Java AWT
 

Similar to String.ppt

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
fedcoordinator
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdf
Ananthi68
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
Indu32
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
Prabu U
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
String handling
String handlingString handling
String handling
ssuser20c32b
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
teach4uin
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation xShahjahan Samoon
 
package
packagepackage
package
sweetysweety8
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulationShahjahan Samoon
 
Java R20 - UNIT-5.docx
Java R20 - UNIT-5.docxJava R20 - UNIT-5.docx
Java R20 - UNIT-5.docx
Pamarthi Kumar
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
Sardar Alam
 
Java R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdfJava R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdf
Pamarthi Kumar
 
Java
JavaJava
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
learnEnglish51
 
Strings in java
Strings in javaStrings in java
Strings in java
Kuppusamy P
 
String and string buffer
String and string bufferString and string buffer
String and string bufferkamal kotecha
 

Similar to String.ppt (20)

javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdf
 
Java string handling
Java string handlingJava string handling
Java string handling
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
 
String Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and InterfacesString Handling, Inheritance, Packages and Interfaces
String Handling, Inheritance, Packages and Interfaces
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
String handling
String handlingString handling
String handling
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
 
String and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
 
package
packagepackage
package
 
String and string manipulation
String and string manipulationString and string manipulation
String and string manipulation
 
M C6java7
M C6java7M C6java7
M C6java7
 
Java R20 - UNIT-5.docx
Java R20 - UNIT-5.docxJava R20 - UNIT-5.docx
Java R20 - UNIT-5.docx
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
 
Java R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdfJava R20 - UNIT-5.pdf
Java R20 - UNIT-5.pdf
 
Java
JavaJava
Java
 
07slide
07slide07slide
07slide
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
 
Strings in java
Strings in javaStrings in java
Strings in java
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
 

More from ajeela mushtaq

Sets automata
Sets automataSets automata
Sets automata
ajeela mushtaq
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
ajeela mushtaq
 
Mail merge
Mail mergeMail merge
Mail merge
ajeela mushtaq
 
Linux hotspot
Linux hotspotLinux hotspot
Linux hotspot
ajeela mushtaq
 
Interfaces .net
Interfaces .netInterfaces .net
Interfaces .net
ajeela mushtaq
 
Incremental
IncrementalIncremental
Incremental
ajeela mushtaq
 
Graphics a buffer
Graphics a bufferGraphics a buffer
Graphics a buffer
ajeela mushtaq
 
Disk allocation methods
Disk allocation methodsDisk allocation methods
Disk allocation methods
ajeela mushtaq
 
Data com prsntation
Data com prsntationData com prsntation
Data com prsntation
ajeela mushtaq
 
Avl tree
Avl treeAvl tree
Avl tree
ajeela mushtaq
 
Dynamic routing
Dynamic routingDynamic routing
Dynamic routing
ajeela mushtaq
 

More from ajeela mushtaq (12)

Sets automata
Sets automataSets automata
Sets automata
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
Mail merge
Mail mergeMail merge
Mail merge
 
Linux hotspot
Linux hotspotLinux hotspot
Linux hotspot
 
Interfaces .net
Interfaces .netInterfaces .net
Interfaces .net
 
Incremental
IncrementalIncremental
Incremental
 
Gprs
GprsGprs
Gprs
 
Graphics a buffer
Graphics a bufferGraphics a buffer
Graphics a buffer
 
Disk allocation methods
Disk allocation methodsDisk allocation methods
Disk allocation methods
 
Data com prsntation
Data com prsntationData com prsntation
Data com prsntation
 
Avl tree
Avl treeAvl tree
Avl tree
 
Dynamic routing
Dynamic routingDynamic routing
Dynamic routing
 

Recently uploaded

一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
ahzuo
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
ukgaet
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
slg6lamcq
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
jerlynmaetalle
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
AbhimanyuSinha9
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
axoqas
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
Timothy Spann
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
ewymefz
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
enxupq
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
nscud
 
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
2023240532
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
g4dpvqap0
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
AnirbanRoy608946
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Linda486226
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
enxupq
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
ewymefz
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
ocavb
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
axoqas
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
74nqk8xf
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP
 

Recently uploaded (20)

一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
一比一原版(UIUC毕业证)伊利诺伊大学|厄巴纳-香槟分校毕业证如何办理
 
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
一比一原版(UVic毕业证)维多利亚大学毕业证成绩单
 
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
一比一原版(Adelaide毕业证书)阿德莱德大学毕业证如何办理
 
The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...The affect of service quality and online reviews on customer loyalty in the E...
The affect of service quality and online reviews on customer loyalty in the E...
 
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...Best best suvichar in gujarati english meaning of this sentence as Silk road ...
Best best suvichar in gujarati english meaning of this sentence as Silk road ...
 
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
哪里卖(usq毕业证书)南昆士兰大学毕业证研究生文凭证书托福证书原版一模一样
 
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
06-04-2024 - NYC Tech Week - Discussion on Vector Databases, Unstructured Dat...
 
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
一比一原版(UofM毕业证)明尼苏达大学毕业证成绩单
 
一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单一比一原版(QU毕业证)皇后大学毕业证成绩单
一比一原版(QU毕业证)皇后大学毕业证成绩单
 
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
一比一原版(CBU毕业证)不列颠海角大学毕业证成绩单
 
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
Quantitative Data AnalysisReliability Analysis (Cronbach Alpha) Common Method...
 
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
一比一原版(爱大毕业证书)爱丁堡大学毕业证如何办理
 
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptxData_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
Data_and_Analytics_Essentials_Architect_an_Analytics_Platform.pptx
 
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdfSample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
Sample_Global Non-invasive Prenatal Testing (NIPT) Market, 2019-2030.pdf
 
一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单一比一原版(YU毕业证)约克大学毕业证成绩单
一比一原版(YU毕业证)约克大学毕业证成绩单
 
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
一比一原版(UPenn毕业证)宾夕法尼亚大学毕业证成绩单
 
一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单一比一原版(TWU毕业证)西三一大学毕业证成绩单
一比一原版(TWU毕业证)西三一大学毕业证成绩单
 
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
做(mqu毕业证书)麦考瑞大学毕业证硕士文凭证书学费发票原版一模一样
 
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
一比一原版(Coventry毕业证书)考文垂大学毕业证如何办理
 
Criminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdfCriminal IP - Threat Hunting Webinar.pdf
Criminal IP - Threat Hunting Webinar.pdf
 

String.ppt

  • 1. BABA GHULAM SHAH BADSHAH UNIVERSITY (RAJOURI) AJEELA MUSHTAQ
  • 2. BABA GHULAM SHAH BADSHAH UNIVERSITY- RAJOURI (J&K). DEPARTMENT OF COMPUTER SCIENCES PRESENTATION TOPIC:- PRESENTED BY:- Ajeela Mushtaq Roll NO:-13-Mcs-15 PRESENTED To:- MR MUZAFFAR AHMAD DAR STRINGbuffer and stringbuilder
  • 3. Strings • Strings, which are widely used in Java programming, are a sequence of characters enquoted with double quotes • In Java programming language, strings are treated as objects. • The Java platform provides the String class to create and manipulate strings.
  • 4. Creating Strings • The most direct way to create a string is to write − String str=“Hello world!”; • Whenever it encounters a string literal in your code, the compiler creates a String object with its value in this case, "Hello world!'. • In java strings does not end with null character.
  • 5. Java StringBuffer class • Java StringBuffer class is used to create mutable (modifiable) string. • The StringBuffer class in java is same as String class except it is mutable i.e. it can be changed. • StringBuffer may have characters and substrings inserted in the middle or appended to the end.
  • 6. StringBuffer Constructors • StringBuffer defines these three constructors: StringBuffer( ) StringBuffer(int size) StringBuffer(String str) • The default constructor (the one with no parameters) reserves room for 16 characters. • The second version accepts an integer argument that explicitly sets the size of the buffer. • The third version accepts a String argument that sets the initial contents of the StringBuffer object and reserves room for 16 more
  • 7. Important methods of StringBuffer class • length( ) and capacity( ) • The current length of a StringBuffer can be found via the length( ) method, while the total allocated capacity can be found through the capacity( ) method. • They have the following general forms: int length( ) int capacity( )
  • 8. setLength( ) • To set the length of the buffer within a StringBuffer object, use setLength( ). Its general form is shown here: void setLength(int len) • Here, len specifies the length of the buffer. This value must be nonnegative.
  • 9. charAt( ) and setCharAt( ) • The value of a single character can be obtained from a StringBuffer via the charAt( ) method. • You can set the value of a character within a StringBuffer using setCharAt(). • Their general forms are shown here: char charAt(int where) void setCharAt(int where, char ch) • For charAt( ), where specifies the index of the character being obtained. • For setCharAt( ),where specifies the index of the character being set,
  • 10. getChars( ) • To copy a substring of a StringBuffer into an array, use the getChars( ) method. • It has this general form: void getChars(int sourceStart, int sourceEnd, char target[ ],int targetStart) • Here, sourceStart specifies the index of the beginning of the substring, and sourceEnd specifies an index that is one past the end of the desired substring.
  • 11. append( ) • The append( ) method concatenates the string representation of any other type of data to the end of the invoking StringBuffer object. • Syntax: StringBuffer append(String str)
  • 12. insert( ) • The insert( ) method inserts one string into another. It is overloaded to accept values of all the simple types, plus Strings, Objects, and CharSequences. • This string is then inserted into the invoking StringBuffer object. These are a few of its forms: StringBuffer insert(int index, String str) StringBuffer insert(int index, char ch) StringBuffer insert(int index, Object obj) • Here, index specifies the index at which point the string will be inserted into the invoking StringBuffer object.
  • 13. reverse( ) • You can reverse the characters within a StringBuffer object using reverse( ), shown here: StringBuffer reverse( ) • This method returns the reversed object on which it was called.
  • 14. substring( ) • You can obtain a portion of a StringBuffer by calling substring( ). It has the following two forms: String substring(int startIndex) String substring(int startIndex, int endIndex)
  • 15. Java StringBuilder class • Java StringBuilder class is used to create mutable (modifiable) string. • The Java StringBuilder class is same as StringBuffer class except that it is non-synchronized. • It is available since JDK 1.5.
  • 16. Important Constructors of StringBuilder class • StringBuilder(): creates an empty string Builder with the initial capacity of 16. • StringBuilder(String str): creates a string Builder with the specified string. • StringBuilder(int length): creates an empty string Builder with the specified capacity as length.
  • 17. Method Description public StringBuilder append() is used to append the specified string with this string. public StringBuilder insert() is used to insert the specified string with this string at the specified position. public StringBuilder replace(int startIndex, int endIndex, String str) is used to replace the string from specified startIndex and endIndex. public StringBuilder delete(int startIndex, int endIndex) is used to delete the string from specified startIndex and endIndex. public StringBuilder reverse() is used to reverse the string. public int capacity() is used to return the current capacity. public int length() is used to return the length of the string i.e. total number of characters. public String substring(int beginIndex) is used to return the substring from the specified beginIndex. public String substring(int beginIndex, int endIndex) is used to return the substring from the specified beginIndex and endIndex.
  • 18. No. StringBuffer StringBuilder 1) StringBuffer is synchronized i.e. thread safe. It means two threads can't call the methods of StringBuffer simultaneously. StringBuilder is non-synchronized i.e. not thread safe. It means two threads can call the methods of StringBuilder simultaneously. 2) StringBuffer is less efficient than StringBuilder. StringBuilder is more efficient than StringBuffer.
  • 19. Thank you…! Have a nice day 19