SlideShare a Scribd company logo
String
Sowmya
Gayathri
Dhivya Bharkavi
What is String?
• String is non-primitive data type and it is also class which is under
java.lang.package.
• String is a collection of characters.
• String is immutable
• Without new keyword we can create object .
• It introduced in JDK1.1.
What is String literals?
• String s=“Java”;
• SCP is part of Heap memory.
“Java” string literal which is
stored in String Constant Pool
(SCP)
SCP
Why String is immutable?
• Strings are constant, values can’t be changed after they are created.
• Because java uses the concept of string literal.
• Suppose, if one reference variable changes the value of the object, it will be
affected to all the reference variables. That is why string objects are
immutable in java.
• So, String is immutable.
Example 1:
concat() method appends the string at the end so strings are
immutable objects.
Java Programming
Java
String Constant Pool
Heap Memory
Example 2:
So, it assign it to the reference variable it
prints Java Programming
Methods
• charAt(), contains(), equals(), equalsIgnoreCase(), toUpperCase, toLowerCase
• length(), compareTo, join(), isEmpty(), length(), replaceAll(), replaceFirst()
• trim(), index(), lastIndexOf(), toString(),concat(), replace(), equals()
• replace(), hashCode(), compareToIgnorCase()
• split()
• substring()
Example 3: subString()
substring(int start/begin index)
substring(int startindex, int endindex)
Overloading
Returns a new string that is
a substring of this string.
Example 4: equals()
Return type is boolean
The String equals() method overrides the equals() method of Object class.
Example 5: equalsIgnoreCase()
Return type is boolean
Example 6: trim()
Example 7: replace()
Return type is char,
charSequence
Replace methods introduced in JDK1.5
Example 8: split()
It returns array of strings computed by splitting this string around matches of the given regular expression.
It introduced in JDK 1.4.
Example 9: split()
It returns array of strings computed by splitting this string around matches of the given regular expression.
It introduced in JDK 1.4.
Overloading
Example 10: concat()
• It returns a string that represents the concatenation of this object's characters
followed by the string argument's characters.
Example 11: contains()
Returns a boolean
Example 12: toString()
Returns a hash code
Example 12:
Using toString method to display a value
Example 13: toUpperCase(), toLowerCase(),
chatAt()
Example 14: length(), join(), isEmpty()
Example 15: replaceAll(), replaceFirst()
Example 16: index()
Overloading
Example 17: lastIndexOf()
Overloading
Example 18: compareTo()
Example 19: compareToIgnoreCase()
Methods Name Introduced
Version
Description Return Type Parameter
charAt() 1.0 The char value at the specified
index. An index ranges
from 0 to length() – 1(length in
interface CharSequence)
The char value at the
specified index of this
string. The
first char value is at
index 0.
index - the index of
the char value.
IsEmpty() 1.6 If it is true, and only
if, length() is 0.
True if length() is 0,
otherwise false
No
concat() 1.0 Concatenates the specified string to
the end of this string.If the length
of the argument string is 0, then
this String object is returned
A string that
represents the
concatenation of this
object's characters
followed by the string
argument's characters.
The String that is
concatenated to the
end of this String.
compareTo() 1.0 The comparison is based on the
Unicode value of each character in
the strings.
The value 0 if the
argument string is
equal to this string
The String to be
compared.
Methods
Name
Introduced
Version
Description Return Type Parameter
contains() 1.5 True if and only if this string
contains the specified sequence
of char values.
True if this string contains s, false
otherwise
The sequence to
search for.
trim() 1.0 a copy of the string, with
leading and trailing whitespace
omitted.
A copy of this string with leading
and trailing white space removed, or
this string if it has no leading or
trailing white space.
No
equals
IgnoreCas
e()
1.0 Compares this String to
another String, ignoring case
considerations
true if the argument is not null and it
represents an
equivalent String ignoring
case; false otherwise.
The String to compare
this String against
length() 1.0 The length of this string. The
length is equal to the number
of Unicode code units in the
string. (charAt in
interface CharSequence)
the length of the sequence of
characters represented by this object.
No
Methods
Name
Introduced
Version
Description Return Type Parameter Exception
replaceAll() 1.4 Replaces each substring of
this string that matches the
given regular
expression with the given
replacement.
The resulting String. the sequence to
search for
PatternSyntaxE
xception
replaceFirst() 1.4 Replaces the first substring
of this string that matches
the given regular
expression with the given
replacement.
The resulting String. the regular
expression to which
this string is to be
matchedreplacement
- the string to be
substituted for the
first match
IndexOutOfBo
undsException
-
compareTo
IgnoreCase()
1.2 Compares two strings
lexicographically, ignoring
case differences.
The specified String is
greater than, equal to,
or less than this
String, ignoring case
considerations.
The String to be
compared.
No
Methods
Name
Introduced
Version
Description Return Type Parameter Exception
toUpperCase() 1.0 Converts all of the
characters in this String to
upper case using the rules
of the default locale.
the String,
converted to
uppercase.
No No
toLoweCase() 1.0 Converts all of the
characters in this String to
lower case using the rules
of the default locale.
the String,
converted to
lowercase.
No No
join() 1.8 A string joined with given
delimiter. In string join
method, delimiter is copied
for each elements.
Joined string with
delimiter.
delimiter : char
value to be added
with each element
elements : char
value to be
attached with
delimiter
NullPointerExce
ption
Methods Name Introduced
Version
Description(Overrides a class
Object)
Return Type Parameter
equals() 1.0 Compares this string to the specified
object. The result is true if and only if
the argument is not null and is
a String object that represents the
same sequence of characters as this
object.
True if the given
object represents
a String equivalent to
this
string, false otherwise
The object to compare
this String against
hashCode() 1.0 A hash code for this string. A hash code value for
this object.
No
toString() 1.0 The toString method for
class Object returns a string consisting
of the name of the class of which the
object is an instance.
This object (which is already a string!)
is itself returned.
A string representation
of the object.
No
Methods
Name
Introduce
d Version
Description(Overloading) Return Type Parameter Exception
substring() 1.0 Returns a new string that is a
substring of this string. The
substring begins with the
character at the specified
index and extends to the end
of this string.
the specified
substring.
beginIndex - the
beginning index,
inclusive.
IndexOutOfBoun
dsException -
substring() 1.0 Returns a new string that is
a substring of this string.
The substring begins at the
specified beginIndex and
extends to the character at
index endIndex - 1. Thus the
length of the substring
is endIndex-beginIndex.
the specified
substring.
beginIndex - the
beginning index,
inclusive.
endIndex - the
ending index,
exclusive.
IndexOutOfBoun
dsException -
Methods
Name
Introduce
d Version
Description(Overloading) Return Type Parameter Exception
replace() 1.0 Returns a new string resulting
from replacing all occurrences
of oldChar in this string
with newChar.
A string derived
from this string by
replacing every
occurrence
of oldChar with ne
wChar.
oldChar - the old
character.newChar
- the new
character.
No
replace() 1.5 Replaces each substring of
this string that matches the
literal target sequence with the
specified literal replacement
sequence.
The
resulting String.
target - The
sequence of char
values to be
replacedreplaceme
nt - The
replacement
sequence of char
values
NullPointerExcept
ion
Methods
Name
Introduced
Version
Description(Overloading) Return Type Parameter Exception
split() 1.4 Splits this string around
matches of the given regular
expression
The array of strings
computed by
splitting this string
around matches of
the given regular
expression
The delimiting
regular expression.
PatternSyntaxExce
ption
split() 1.4 Splits this string around
matches of the given regular
expression.
the array of strings
computed by
splitting this string
around matches of
the given regular
expression.
regex - the
delimiting regular
expressionlimit -
the result
threshold, as
described above
PatternSyntaxExce
ption -
Methods
Name
Introduced
Version
Description(Overloading) Return Type Parameter Exception
index() 1.0 The index within this string
of the first occurrence of the
specified character.
the index of the
first occurrence of
the character in the
character sequence
represented by this
object
a character
(Unicode code
point).
No
index() 1.0
“ “
fromIndex - the
index to start the
search from.
No
index() 1.0
“
The index of the
first occurrence of
the specified
substring
the substring to
search for.
No
index() 1.0 “ “ fromIndex - the
index from which
to start the search.
No
Methods
Name
Introduced
Version
Description(Overloading) Return Type Parameter Exception
lastIndex() 1.0 The index within this string
of the last occurrence of the
specified character.
the index of the last
occurrence of the
character in the
character sequence
represented by this
object
a character
(Unicode code
point).
No
lastIndex() 1.0
“ “
fromIndex - the
index to start the
search from.
No
lastIndex() 1.0
“
The index of the
first occurrence of
the specified
substring
the substring to
search for.
No
lastIndex() 1.0 “ “ fromIndex - the
index from which
to start the search.
No
What is String Buffer?
• StringBuffer is mutable String.
• Java StringBuffer class is (synchronized )thread-safe i.e. multiple threads
cannot access it simultaneously.
• So it is safe and will result in an order.
Why String Buffer is mutable?
append() it return many data types
Overloading
Methods
• append(), replace(), setCharAt()
• insert()
• delete()
• reverse()
• length()
• charAt()
• deleteChatAt()
• setLength()
Methods
Name
Introduced
Version
Description Return Type Parameter Exception
delete() 1.2 Removes the characters in a
substring of this sequence.
This object. start - The
beginning index,
inclusive.end - The
ending index,
exclusive.
StringIndexOutOf
BoundsException
deleteCharAt() 1.2 Removes the char at the
specified position in this
sequence. This sequence is
shortened by one char.
“ Index of char to
remove
“
replace() 1.2 Replaces the characters in a
substring of this sequence
with characters in the
specified String.
“ start - The
beginning index,
inclusive.end - The
ending index,
exclusive.str -
String that will
replace previous
contents.
“
Methods
Name
Introduced
Version
Description Return Type Parameter Exception
reverse() 1.0.2 Causes this character
sequence to be replaced by
the reverse of the sequence
A reference to this
object.
No No
setLength() 1.0 Sets the length of the
character sequence. The
sequence is changed to a new
character sequence whose
length is specified by the
argument
No The new length IndexOutOfBoun
dsException
charAt() 1.0 Returns the char value in this
sequence at the specified
index.
the char value at the
specified index
index - the index
of the
desired char value.
IndexOutOfBoun
dsException
setCharAt() 1.0 The character at the specified
index is set.
No index - the index
of the character to
modify.ch - the
new character.
IndexOutOfBoun
dsException
Methods
Name
Introduced
Version
Description(Overloading) Return Type Parameter Exception
append() 1.0 Appends the specified string
to this character sequence.
A reference to this
object.
A string. No
insert() 1.0 Inserts the string into this
character sequence
A reference to this
object.
offset - the
offset.str - a string.
StringIndexOutOf
BoundsException
Append() and insert() methods has many types in StringBuffer.
Example 1: delete(), deleteCharAt()
Example 2: reverse(), replace()
Example 3: setLength()
Example 4:charAt(), setCharAt()
Example 5: insert()
Overloading
What is String Builder?
• StringBuilder is mutable String.
• The Java StringBuilder class is same as StringBuffer class except that it is
non-synchronized (not thread-safe).
• It is available since JDK 1.5.
Methods
• append(), replace(), subsequence(), substring(), charAt() , trimToSize()
• insert() delete(), capacity(), ensureCapacity(), reverse(), length()
• StringBuffer methods is similar to StringBuilder
Methods
Name
Introduced
Version
Description(Overloading) Return Type Parameter Exception
subsequence
()
1.5 the new character sequence
from given start index to
exclusive end index value of
this sequence.
The
subSequence(int
start, int end)
method returns the
specified
subsequence.
The start and end
index of a
subsequence.
IndexOutOfBou
ndsException
trimToSize(
)
1.5 To reduce the storage used
for the character sequence.
No No No
reverse() 1.5 Causes this character
sequence to be replaced by
the reverse of the sequence
A reference to this
object.
No No
Example 1:reverse()
Overrides in a String Buffer
Example 2: subsequence()
Example 3: trimToSize()
Difference
String String Buffer
It is immutable It is mutable.
String is slow and consumes more memory String is fast and consumes less memory
When you concat too many strings because every
time it creates new instance.
When you cancat strings.
1.0 1.0
Java.lang.package Java.lang.pakage
Difference
StringBuffer String Builder
It is immutable It is immutable.
It is synchronized i.e. thread safe. It is non-synchronized i.e. not thread safe.
It means two threads can't call the methods of
StringBuffer simultaneously.
It means two threads can call the methods of
StringBuilder simultaneously.
1.0 1.5
It is less efficient. It is more efficient.
Ad

More Related Content

What's hot (20)

String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)String Builder & String Buffer (Java Programming)
String Builder & String Buffer (Java Programming)
Anwar Hasan Shuvo
 
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Data Types & Variables in JAVA
Data Types & Variables in JAVAData Types & Variables in JAVA
Data Types & Variables in JAVA
Ankita Totala
 
JAVA AWT
JAVA AWTJAVA AWT
JAVA AWT
shanmuga rajan
 
Arrays in Java
Arrays in JavaArrays in Java
Arrays in Java
Naz Abdalla
 
Java - Collections framework
Java - Collections frameworkJava - Collections framework
Java - Collections framework
Riccardo Cardin
 
Java String
Java StringJava String
Java String
Java2Blog
 
StringTokenizer in java
StringTokenizer in javaStringTokenizer in java
StringTokenizer in java
Muthukumaran Subramanian
 
Wrapper classes
Wrapper classes Wrapper classes
Wrapper classes
Kongu Engineering College, Perundurai, Erode
 
Dynamic memory allocation in c++
Dynamic memory allocation in c++Dynamic memory allocation in c++
Dynamic memory allocation in c++
Tech_MX
 
Control statements in java
Control statements in javaControl statements in java
Control statements in java
Madishetty Prathibha
 
Java interfaces
Java interfacesJava interfaces
Java interfaces
Raja Sekhar
 
Inheritance and Polymorphism
Inheritance and PolymorphismInheritance and Polymorphism
Inheritance and Polymorphism
BG Java EE Course
 
Inheritance in java
Inheritance in javaInheritance in java
Inheritance in java
Tech_MX
 
Packages in java
Packages in javaPackages in java
Packages in java
Kavitha713564
 
Strings in Java
Strings in Java Strings in Java
Strings in Java
Hitesh-Java
 
Polymorphism In Java
Polymorphism In JavaPolymorphism In Java
Polymorphism In Java
Spotle.ai
 
Interface in java
Interface in javaInterface in java
Interface in java
PhD Research Scholar
 
9 python data structure-2
9 python data structure-29 python data structure-2
9 python data structure-2
Prof. Dr. K. Adisesha
 

Similar to String, string builder, string buffer (20)

Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
C# String
C# StringC# String
C# String
Raghuveer Guthikonda
 
Strings
StringsStrings
Strings
naslin prestilda
 
13string in c#
13string in c#13string in c#
13string in c#
Sireesh K
 
Strings power point in detail with examples
Strings power point in detail with examplesStrings power point in detail with examples
Strings power point in detail with examples
rabiyanaseer1
 
Computer programming 2 Lesson 10
Computer programming 2  Lesson 10Computer programming 2  Lesson 10
Computer programming 2 Lesson 10
MLG College of Learning, Inc
 
Adv. python regular expression by Rj
Adv. python regular expression by RjAdv. python regular expression by Rj
Adv. python regular expression by Rj
Shree M.L.Kakadiya MCA mahila college, Amreli
 
M C6java7
M C6java7M C6java7
M C6java7
mbruggen
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
SanthiyaAK
 
package
packagepackage
package
sweetysweety8
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
MegMeg17
 
Xtend Programming Language
Xtend Programming LanguageXtend Programming Language
Xtend Programming Language
Mikhail Barash
 
LISP: Type specifiers in lisp
LISP: Type specifiers in lispLISP: Type specifiers in lisp
LISP: Type specifiers in lisp
LISP Content
 
LISP: Type specifiers in lisp
LISP: Type specifiers in lispLISP: Type specifiers in lisp
LISP: Type specifiers in lisp
DataminingTools Inc
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
Mr Examples
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
İbrahim Kürce
 
Java scanner, everything you need to know about Java Scanner
Java scanner, everything you need to know about Java ScannerJava scanner, everything you need to know about Java Scanner
Java scanner, everything you need to know about Java Scanner
Edward Nyang'ali
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptxDOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
meganath16032003
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
13string in c#
13string in c#13string in c#
13string in c#
Sireesh K
 
Strings power point in detail with examples
Strings power point in detail with examplesStrings power point in detail with examples
Strings power point in detail with examples
rabiyanaseer1
 
Module 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdfModule 6 - String Manipulation.pdf
Module 6 - String Manipulation.pdf
MegMeg17
 
Xtend Programming Language
Xtend Programming LanguageXtend Programming Language
Xtend Programming Language
Mikhail Barash
 
LISP: Type specifiers in lisp
LISP: Type specifiers in lispLISP: Type specifiers in lisp
LISP: Type specifiers in lisp
LISP Content
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
 
Python Strings Methods
Python Strings MethodsPython Strings Methods
Python Strings Methods
Mr Examples
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIsOCA Java SE 8 Exam Chapter 3 Core Java APIs
OCA Java SE 8 Exam Chapter 3 Core Java APIs
İbrahim Kürce
 
Java scanner, everything you need to know about Java Scanner
Java scanner, everything you need to know about Java ScannerJava scanner, everything you need to know about Java Scanner
Java scanner, everything you need to know about Java Scanner
Edward Nyang'ali
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptxDOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
meganath16032003
 
Ad

More from SSN College of Engineering, Kalavakkam (20)

ECG
ECG ECG
ECG
SSN College of Engineering, Kalavakkam
 
Localization, Classification, and Evaluation.pdf
Localization, Classification, and Evaluation.pdfLocalization, Classification, and Evaluation.pdf
Localization, Classification, and Evaluation.pdf
SSN College of Engineering, Kalavakkam
 
ADBMS 3a
ADBMS   3aADBMS   3a
ADBMS 3a
SSN College of Engineering, Kalavakkam
 
Exercise 5
Exercise   5Exercise   5
Exercise 5
SSN College of Engineering, Kalavakkam
 
ADBMS Unit-II c
ADBMS Unit-II cADBMS Unit-II c
ADBMS Unit-II c
SSN College of Engineering, Kalavakkam
 
ADBMS Unit-II b
ADBMS Unit-II bADBMS Unit-II b
ADBMS Unit-II b
SSN College of Engineering, Kalavakkam
 
Database Management System - 2a
Database Management System - 2aDatabase Management System - 2a
Database Management System - 2a
SSN College of Engineering, Kalavakkam
 
Database Management System
Database Management SystemDatabase Management System
Database Management System
SSN College of Engineering, Kalavakkam
 
Unit III - Inventory Problems
Unit III - Inventory ProblemsUnit III - Inventory Problems
Unit III - Inventory Problems
SSN College of Engineering, Kalavakkam
 
Unit II B - Game Theory
Unit II B - Game TheoryUnit II B - Game Theory
Unit II B - Game Theory
SSN College of Engineering, Kalavakkam
 
Unit II A - Game Theory
Unit II A - Game TheoryUnit II A - Game Theory
Unit II A - Game Theory
SSN College of Engineering, Kalavakkam
 
Unit V - Queuing Theory
Unit V - Queuing TheoryUnit V - Queuing Theory
Unit V - Queuing Theory
SSN College of Engineering, Kalavakkam
 
Unit IV-Project Management
Unit IV-Project ManagementUnit IV-Project Management
Unit IV-Project Management
SSN College of Engineering, Kalavakkam
 
Unit I-B
Unit I-BUnit I-B
Unit I-B
SSN College of Engineering, Kalavakkam
 
Unit I-A
Unit I-AUnit I-A
Unit I-A
SSN College of Engineering, Kalavakkam
 
Web technology Unit-II Part-C
Web technology Unit-II Part-CWeb technology Unit-II Part-C
Web technology Unit-II Part-C
SSN College of Engineering, Kalavakkam
 
Data structure Unit-I Part-C
Data structure Unit-I Part-CData structure Unit-I Part-C
Data structure Unit-I Part-C
SSN College of Engineering, Kalavakkam
 
Data structure unit I part B
Data structure unit I part BData structure unit I part B
Data structure unit I part B
SSN College of Engineering, Kalavakkam
 
Web technology Unit-II Part A
Web technology Unit-II Part AWeb technology Unit-II Part A
Web technology Unit-II Part A
SSN College of Engineering, Kalavakkam
 
Data structure Unit-I Part A
Data structure Unit-I Part AData structure Unit-I Part A
Data structure Unit-I Part A
SSN College of Engineering, Kalavakkam
 
Ad

Recently uploaded (20)

How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
How to Clean Your Contacts Using the Deduplication Menu in Odoo 18
Celine George
 
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast BrooklynBridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
Bridging the Transit Gap: Equity Drive Feeder Bus Design for Southeast Brooklyn
i4jd41bk
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdfRanking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Ranking_Felicidade_2024_com_Educacao_Marketing Educacional_V2.pdf
Rafael Villas B
 
Kenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 CohortKenan Fellows Participants, Projects 2025-26 Cohort
Kenan Fellows Participants, Projects 2025-26 Cohort
EducationNC
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living WorkshopLDMMIA Reiki Yoga S5 Daily Living Workshop
LDMMIA Reiki Yoga S5 Daily Living Workshop
LDM Mia eStudios
 
antiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidenceantiquity of writing in ancient India- literary & archaeological evidence
antiquity of writing in ancient India- literary & archaeological evidence
PrachiSontakke5
 
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and GuestsLDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDMMIA Reiki News Ed3 Vol1 For Team and Guests
LDM Mia eStudios
 
Lecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptxLecture 4 INSECT CUTICLE and moulting.pptx
Lecture 4 INSECT CUTICLE and moulting.pptx
Arshad Shaikh
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Drugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdfDrugs in Anaesthesia and Intensive Care,.pdf
Drugs in Anaesthesia and Intensive Care,.pdf
crewot855
 
How to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 SalesHow to Manage Upselling in Odoo 18 Sales
How to Manage Upselling in Odoo 18 Sales
Celine George
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptxU3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
U3 ANTITUBERCULAR DRUGS Pharmacology 3.pptx
Mayuri Chavan
 
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptxTERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
TERMINOLOGIES,GRIEF PROCESS AND LOSS AMD ITS TYPES .pptx
PoojaSen20
 
Ajanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of HistoryAjanta Paintings: Study as a Source of History
Ajanta Paintings: Study as a Source of History
Virag Sontakke
 
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
Drive Supporter Growth from Awareness to Advocacy with TechSoup Marketing Ser...
TechSoup
 
Tax evasion, Tax planning & Tax avoidance.pptx
Tax evasion, Tax  planning &  Tax avoidance.pptxTax evasion, Tax  planning &  Tax avoidance.pptx
Tax evasion, Tax planning & Tax avoidance.pptx
manishbaidya2017
 

String, string builder, string buffer

  • 2. What is String? • String is non-primitive data type and it is also class which is under java.lang.package. • String is a collection of characters. • String is immutable • Without new keyword we can create object . • It introduced in JDK1.1.
  • 3. What is String literals? • String s=“Java”; • SCP is part of Heap memory. “Java” string literal which is stored in String Constant Pool (SCP) SCP
  • 4. Why String is immutable? • Strings are constant, values can’t be changed after they are created. • Because java uses the concept of string literal. • Suppose, if one reference variable changes the value of the object, it will be affected to all the reference variables. That is why string objects are immutable in java. • So, String is immutable.
  • 5. Example 1: concat() method appends the string at the end so strings are immutable objects.
  • 7. Example 2: So, it assign it to the reference variable it prints Java Programming
  • 8. Methods • charAt(), contains(), equals(), equalsIgnoreCase(), toUpperCase, toLowerCase • length(), compareTo, join(), isEmpty(), length(), replaceAll(), replaceFirst() • trim(), index(), lastIndexOf(), toString(),concat(), replace(), equals() • replace(), hashCode(), compareToIgnorCase() • split() • substring()
  • 9. Example 3: subString() substring(int start/begin index) substring(int startindex, int endindex) Overloading Returns a new string that is a substring of this string.
  • 10. Example 4: equals() Return type is boolean The String equals() method overrides the equals() method of Object class.
  • 13. Example 7: replace() Return type is char, charSequence Replace methods introduced in JDK1.5
  • 14. Example 8: split() It returns array of strings computed by splitting this string around matches of the given regular expression. It introduced in JDK 1.4.
  • 15. Example 9: split() It returns array of strings computed by splitting this string around matches of the given regular expression. It introduced in JDK 1.4. Overloading
  • 16. Example 10: concat() • It returns a string that represents the concatenation of this object's characters followed by the string argument's characters.
  • 19. Example 12: Using toString method to display a value
  • 20. Example 13: toUpperCase(), toLowerCase(), chatAt()
  • 21. Example 14: length(), join(), isEmpty()
  • 22. Example 15: replaceAll(), replaceFirst()
  • 27. Methods Name Introduced Version Description Return Type Parameter charAt() 1.0 The char value at the specified index. An index ranges from 0 to length() – 1(length in interface CharSequence) The char value at the specified index of this string. The first char value is at index 0. index - the index of the char value. IsEmpty() 1.6 If it is true, and only if, length() is 0. True if length() is 0, otherwise false No concat() 1.0 Concatenates the specified string to the end of this string.If the length of the argument string is 0, then this String object is returned A string that represents the concatenation of this object's characters followed by the string argument's characters. The String that is concatenated to the end of this String. compareTo() 1.0 The comparison is based on the Unicode value of each character in the strings. The value 0 if the argument string is equal to this string The String to be compared.
  • 28. Methods Name Introduced Version Description Return Type Parameter contains() 1.5 True if and only if this string contains the specified sequence of char values. True if this string contains s, false otherwise The sequence to search for. trim() 1.0 a copy of the string, with leading and trailing whitespace omitted. A copy of this string with leading and trailing white space removed, or this string if it has no leading or trailing white space. No equals IgnoreCas e() 1.0 Compares this String to another String, ignoring case considerations true if the argument is not null and it represents an equivalent String ignoring case; false otherwise. The String to compare this String against length() 1.0 The length of this string. The length is equal to the number of Unicode code units in the string. (charAt in interface CharSequence) the length of the sequence of characters represented by this object. No
  • 29. Methods Name Introduced Version Description Return Type Parameter Exception replaceAll() 1.4 Replaces each substring of this string that matches the given regular expression with the given replacement. The resulting String. the sequence to search for PatternSyntaxE xception replaceFirst() 1.4 Replaces the first substring of this string that matches the given regular expression with the given replacement. The resulting String. the regular expression to which this string is to be matchedreplacement - the string to be substituted for the first match IndexOutOfBo undsException - compareTo IgnoreCase() 1.2 Compares two strings lexicographically, ignoring case differences. The specified String is greater than, equal to, or less than this String, ignoring case considerations. The String to be compared. No
  • 30. Methods Name Introduced Version Description Return Type Parameter Exception toUpperCase() 1.0 Converts all of the characters in this String to upper case using the rules of the default locale. the String, converted to uppercase. No No toLoweCase() 1.0 Converts all of the characters in this String to lower case using the rules of the default locale. the String, converted to lowercase. No No join() 1.8 A string joined with given delimiter. In string join method, delimiter is copied for each elements. Joined string with delimiter. delimiter : char value to be added with each element elements : char value to be attached with delimiter NullPointerExce ption
  • 31. Methods Name Introduced Version Description(Overrides a class Object) Return Type Parameter equals() 1.0 Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object. True if the given object represents a String equivalent to this string, false otherwise The object to compare this String against hashCode() 1.0 A hash code for this string. A hash code value for this object. No toString() 1.0 The toString method for class Object returns a string consisting of the name of the class of which the object is an instance. This object (which is already a string!) is itself returned. A string representation of the object. No
  • 32. Methods Name Introduce d Version Description(Overloading) Return Type Parameter Exception substring() 1.0 Returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string. the specified substring. beginIndex - the beginning index, inclusive. IndexOutOfBoun dsException - substring() 1.0 Returns a new string that is a substring of this string. The substring begins at the specified beginIndex and extends to the character at index endIndex - 1. Thus the length of the substring is endIndex-beginIndex. the specified substring. beginIndex - the beginning index, inclusive. endIndex - the ending index, exclusive. IndexOutOfBoun dsException -
  • 33. Methods Name Introduce d Version Description(Overloading) Return Type Parameter Exception replace() 1.0 Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar. A string derived from this string by replacing every occurrence of oldChar with ne wChar. oldChar - the old character.newChar - the new character. No replace() 1.5 Replaces each substring of this string that matches the literal target sequence with the specified literal replacement sequence. The resulting String. target - The sequence of char values to be replacedreplaceme nt - The replacement sequence of char values NullPointerExcept ion
  • 34. Methods Name Introduced Version Description(Overloading) Return Type Parameter Exception split() 1.4 Splits this string around matches of the given regular expression The array of strings computed by splitting this string around matches of the given regular expression The delimiting regular expression. PatternSyntaxExce ption split() 1.4 Splits this string around matches of the given regular expression. the array of strings computed by splitting this string around matches of the given regular expression. regex - the delimiting regular expressionlimit - the result threshold, as described above PatternSyntaxExce ption -
  • 35. Methods Name Introduced Version Description(Overloading) Return Type Parameter Exception index() 1.0 The index within this string of the first occurrence of the specified character. the index of the first occurrence of the character in the character sequence represented by this object a character (Unicode code point). No index() 1.0 “ “ fromIndex - the index to start the search from. No index() 1.0 “ The index of the first occurrence of the specified substring the substring to search for. No index() 1.0 “ “ fromIndex - the index from which to start the search. No
  • 36. Methods Name Introduced Version Description(Overloading) Return Type Parameter Exception lastIndex() 1.0 The index within this string of the last occurrence of the specified character. the index of the last occurrence of the character in the character sequence represented by this object a character (Unicode code point). No lastIndex() 1.0 “ “ fromIndex - the index to start the search from. No lastIndex() 1.0 “ The index of the first occurrence of the specified substring the substring to search for. No lastIndex() 1.0 “ “ fromIndex - the index from which to start the search. No
  • 37. What is String Buffer? • StringBuffer is mutable String. • Java StringBuffer class is (synchronized )thread-safe i.e. multiple threads cannot access it simultaneously. • So it is safe and will result in an order.
  • 38. Why String Buffer is mutable? append() it return many data types Overloading
  • 39. Methods • append(), replace(), setCharAt() • insert() • delete() • reverse() • length() • charAt() • deleteChatAt() • setLength()
  • 40. Methods Name Introduced Version Description Return Type Parameter Exception delete() 1.2 Removes the characters in a substring of this sequence. This object. start - The beginning index, inclusive.end - The ending index, exclusive. StringIndexOutOf BoundsException deleteCharAt() 1.2 Removes the char at the specified position in this sequence. This sequence is shortened by one char. “ Index of char to remove “ replace() 1.2 Replaces the characters in a substring of this sequence with characters in the specified String. “ start - The beginning index, inclusive.end - The ending index, exclusive.str - String that will replace previous contents. “
  • 41. Methods Name Introduced Version Description Return Type Parameter Exception reverse() 1.0.2 Causes this character sequence to be replaced by the reverse of the sequence A reference to this object. No No setLength() 1.0 Sets the length of the character sequence. The sequence is changed to a new character sequence whose length is specified by the argument No The new length IndexOutOfBoun dsException charAt() 1.0 Returns the char value in this sequence at the specified index. the char value at the specified index index - the index of the desired char value. IndexOutOfBoun dsException setCharAt() 1.0 The character at the specified index is set. No index - the index of the character to modify.ch - the new character. IndexOutOfBoun dsException
  • 42. Methods Name Introduced Version Description(Overloading) Return Type Parameter Exception append() 1.0 Appends the specified string to this character sequence. A reference to this object. A string. No insert() 1.0 Inserts the string into this character sequence A reference to this object. offset - the offset.str - a string. StringIndexOutOf BoundsException Append() and insert() methods has many types in StringBuffer.
  • 43. Example 1: delete(), deleteCharAt()
  • 48. What is String Builder? • StringBuilder is mutable String. • The Java StringBuilder class is same as StringBuffer class except that it is non-synchronized (not thread-safe). • It is available since JDK 1.5.
  • 49. Methods • append(), replace(), subsequence(), substring(), charAt() , trimToSize() • insert() delete(), capacity(), ensureCapacity(), reverse(), length() • StringBuffer methods is similar to StringBuilder
  • 50. Methods Name Introduced Version Description(Overloading) Return Type Parameter Exception subsequence () 1.5 the new character sequence from given start index to exclusive end index value of this sequence. The subSequence(int start, int end) method returns the specified subsequence. The start and end index of a subsequence. IndexOutOfBou ndsException trimToSize( ) 1.5 To reduce the storage used for the character sequence. No No No reverse() 1.5 Causes this character sequence to be replaced by the reverse of the sequence A reference to this object. No No
  • 54. Difference String String Buffer It is immutable It is mutable. String is slow and consumes more memory String is fast and consumes less memory When you concat too many strings because every time it creates new instance. When you cancat strings. 1.0 1.0 Java.lang.package Java.lang.pakage
  • 55. Difference StringBuffer String Builder It is immutable It is immutable. It is synchronized i.e. thread safe. It is non-synchronized i.e. not thread safe. It means two threads can't call the methods of StringBuffer simultaneously. It means two threads can call the methods of StringBuilder simultaneously. 1.0 1.5 It is less efficient. It is more efficient.
  翻译: