SlideShare a Scribd company logo
Java : Strings
Outline
▪ What is string ?
▪ How to createString object?
▪ Some important operations of strings
▪ Some important string class methods
▪ StringBuffer class & StringBuilder class
▪ Difference between String andStringBuffer
▪ Difference between StringBuffer andStringBuilder
What is String ?
▪ Strings, which are widely used in Java
programming, are a sequence of characters. In
Java programming language, strings are
treated as objects.
▪ The Java platform provides the String class to
create and manipulate strings.
Important Notes about String
▪ String – Object or Primitive?
- Strings could be considered a primitive type in Java, but in fact they are not.
As a String is actually made up of an array of char primitives.
▪ String objects are immutable!
-That means once a string object is created it cannot be altered. For mutable
string, you can use StringBuffer and StringBuilder classes.
[An object whose state cannot be changed after it is created is known as an
Immutable object. String, Integer, Byte, Short, Float, Double and all other wrapper
class's objects are immutable.]
How to createString object?
There are two ways to createString object:
1.By string literal
For Example:
String s="welcome";
2.By new keyword
For Example:
String s=newString("Welcome");
Java String Example
Output :
java
strings
example
Some important operations of strings
▪ StringConcatenation
▪ StringComparison
▪ Substring
▪ Length ofString etc.
String Concatenation
▪ There are 2 methods to concatenate two or more string.
Concatenate
two or more
string.
Using
concat()
method
Using +
operator
String Comparison
▪ String comparison can be done in 3 ways.
String
Comparison
Using
equals()
method
Using ==
operator
By
CompareTo()
method
String Comparison Example
Substring in Java
▪ A part of string is called substring. In other words, substring is a subset of another string.
▪ We can get substring from the given string object by one of the two methods:
1. publicString substring(int startIndex):
2. publicString substring(int startIndex, int endIndex):
Length of String
finds the length of the string. It returns count of total
▪ The java string length() method
number of characters.
Some more string class methods
▪ The java.lang.String class provides a lot of methods to work on string. By the help of
these methods, we can perform operations on strings.
▪ Here we will learn about the following methods :
1. charAt()
2. contains()
3. getChars()
4. indexOf()
5. replace()
6. toCharArray()
7. toLowerCase()
8. toUpperCase()
charAt() & contains()
 charAt() = returns a char value at the given index number.The index number starts from 0.
 contains() = searches the sequence of characters in this string. It returns true if sequence of char values
are found in this string otherwise returns false.
getChars()
 getChars() = copies the content of this string into specified char array.There are 4
arguments passed in getChars() method. It throws StringIndexOutOfBoundsException
if beginIndex is greater than endIndex.
indexOf()
 indexOf() = returns index
of given character value
or substring. If it is not
found, it returns -1. The
index counter starts from
zero.
replace()
 replace() = returns a string replacing all the old char orCharSequence to new char or
CharSequence.
toCharArray()
 toCharArray() = converts this string into character array.
toLowerCase() & toUpperCase()
 toLowerCase() = returns the string in lowercase letter. In other words, it converts all
characters of the string into lower case letter.
 toUpperCase() =returns the string in uppercase letter. In other words, it converts all
characters of the string into upper case letter.
Java StringBuffer class
▪ Java StringBuffer class is used to created mutable (modifiable) string.
▪ ImportantConstructors of StringBuffer class:
 StringBuffer(): creates an empty string buffer with the initial capacity of 16.
 StringBuffer(String str): creates a string buffer with the specified string.
 StringBuffer(int capacity): creates an empty string buffer with the specified capacity as length.
▪ Important methods of StringBuffer class:
 append(String s): is used to append the specified string with this string.The append() method is
overloaded like append(char), append(boolean), append(int), append(float), append(double) etc.
 insert(int offset, String s): is used to insert the specified string with this string at the specified position.
The insert() method is overloaded like insert(int, char), insert(int, boolean), insert(int, int), insert(int,
float), insert(int, double) etc.
 replace(int startIndex, int endIndex,String str): is used to replace the string from specified startIndex
and endIndex.
 delete(int startIndex, int endIndex): is used to delete the string from specified startIndex and endIndex.
 reverse(): is used to reverse the string.
 capacity(): is used to return the current capacity.
Java StringBuilder class
▪ Java StringBuilder class is used to create mutable (modifiable)
string.TheJavaStringBuilder class is same as StringBuffer class
except that it is non-synchronized.
Example of using StringBuffer & StringBuilder class
Difference between String and StringBuffer
No. String StringBuffer
1) String class is immutable. StringBuffer class is mutable.
2) String is slow and consumes more memory when
you concat too many strings because every time
it creates new instance.
StringBuffer is fast and consumes less memory
when you cancat strings.
3) String class overrides the equals() method of
Object class. So you can compare the contents of
two strings by equals() method.
StringBuffer class doesn't override the equals()
method of Object class.
Difference between StringBuffer and StringBuilder
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 thanStringBuilder. StringBuilder
StringBuffer.
is more efficient than
Thanks to all
Ad

More Related Content

Similar to In the given example only one object will be created. Firstly JVM will not find any string object with the value “Welcome” in the string (20)

STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVASTRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
pkavithascs
 
Java Strings methods and operations.ppt
Java Strings  methods and operations.pptJava Strings  methods and operations.ppt
Java Strings methods and operations.ppt
JyothiAmpally
 
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
 
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
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
 
Java String
Java String Java String
Java String
SATYAM SHRIVASTAV
 
package
packagepackage
package
sweetysweety8
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
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
 
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
21CS642 Module 3 Strings PPT.pptx VI SEM CSE21CS642 Module 3 Strings PPT.pptx VI SEM CSE
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
VENKATESHBHAT25
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdf
Ananthi68
 
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 and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan Samoon
 
Day_5.1.pptx
Day_5.1.pptxDay_5.1.pptx
Day_5.1.pptx
ishasharma835109
 
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
OUM SAOKOSAL
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
Infoviaan Technologies
 
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptxDOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
meganath16032003
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
Debasish Pratihari
 
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
hossamghareb681
 
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVASTRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
STRING CLASS AND STRING BUFFER CLASS CONCEPTS IN JAVA
pkavithascs
 
Java Strings methods and operations.ppt
Java Strings  methods and operations.pptJava Strings  methods and operations.ppt
Java Strings methods and operations.ppt
JyothiAmpally
 
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
 
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
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
 
String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
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
 
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
21CS642 Module 3 Strings PPT.pptx VI SEM CSE21CS642 Module 3 Strings PPT.pptx VI SEM CSE
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
VENKATESHBHAT25
 
3.7_StringBuilder.pdf
3.7_StringBuilder.pdf3.7_StringBuilder.pdf
3.7_StringBuilder.pdf
Ananthi68
 
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 and string manipulation x
String and string manipulation xString and string manipulation x
String and string manipulation x
Shahjahan Samoon
 
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptxDOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
DOC-20240802-WA0004dgcuhfgbjhfucjv6du..pptx
meganath16032003
 
Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
 
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
M251_Meeting 2_updated_2.pdf(M251_Meeting 2_updated_2.pdf)
hossamghareb681
 

More from Indu32 (12)

jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc pptjdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
Indu32
 
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
Indu32
 
Introduction to MySQL commands mysql presentation 22.pptx
Introduction to MySQL commands   mysql presentation 22.pptxIntroduction to MySQL commands   mysql presentation 22.pptx
Introduction to MySQL commands mysql presentation 22.pptx
Indu32
 
unit8_jdbc.pdf mysql and java jdbc connection
unit8_jdbc.pdf mysql and java jdbc connectionunit8_jdbc.pdf mysql and java jdbc connection
unit8_jdbc.pdf mysql and java jdbc connection
Indu32
 
css front end development , designing web page
css front end development , designing web pagecss front end development , designing web page
css front end development , designing web page
Indu32
 
CSS presentation for beginners where they can understand easily
CSS presentation for beginners where they can understand easilyCSS presentation for beginners where they can understand easily
CSS presentation for beginners where they can understand easily
Indu32
 
html webpage development different tags used
html webpage development different tags usedhtml webpage development different tags used
html webpage development different tags used
Indu32
 
design patter related ppt and presentation
design patter related ppt and presentationdesign patter related ppt and presentation
design patter related ppt and presentation
Indu32
 
Web development ppt used to design web applocation
Web development ppt  used to design web applocationWeb development ppt  used to design web applocation
Web development ppt used to design web applocation
Indu32
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
Indu32
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
Indu32
 
java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...
Indu32
 
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc pptjdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
jdbcppt.pptx , jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt jdbc ppt
Indu32
 
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
java-basics-1.pdf jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjghjgkj df jfjf hjg...
Indu32
 
Introduction to MySQL commands mysql presentation 22.pptx
Introduction to MySQL commands   mysql presentation 22.pptxIntroduction to MySQL commands   mysql presentation 22.pptx
Introduction to MySQL commands mysql presentation 22.pptx
Indu32
 
unit8_jdbc.pdf mysql and java jdbc connection
unit8_jdbc.pdf mysql and java jdbc connectionunit8_jdbc.pdf mysql and java jdbc connection
unit8_jdbc.pdf mysql and java jdbc connection
Indu32
 
css front end development , designing web page
css front end development , designing web pagecss front end development , designing web page
css front end development , designing web page
Indu32
 
CSS presentation for beginners where they can understand easily
CSS presentation for beginners where they can understand easilyCSS presentation for beginners where they can understand easily
CSS presentation for beginners where they can understand easily
Indu32
 
html webpage development different tags used
html webpage development different tags usedhtml webpage development different tags used
html webpage development different tags used
Indu32
 
design patter related ppt and presentation
design patter related ppt and presentationdesign patter related ppt and presentation
design patter related ppt and presentation
Indu32
 
Web development ppt used to design web applocation
Web development ppt  used to design web applocationWeb development ppt  used to design web applocation
Web development ppt used to design web applocation
Indu32
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
Indu32
 
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...In this page, we will learn about the basics of OOPs. Object-Oriented Program...
In this page, we will learn about the basics of OOPs. Object-Oriented Program...
Indu32
 
java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...java basic ppt introduction, The Java language is known for its robustness, s...
java basic ppt introduction, The Java language is known for its robustness, s...
Indu32
 
Ad

Recently uploaded (20)

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
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
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
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
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
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
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
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
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
 
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
 
Cultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptxCultivation Practice of Turmeric in Nepal.pptx
Cultivation Practice of Turmeric in Nepal.pptx
UmeshTimilsina1
 
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
 
How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18How to Configure Public Holidays & Mandatory Days in Odoo 18
How to Configure Public Holidays & Mandatory Days in Odoo 18
Celine George
 
Form View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo SlidesForm View Attributes in Odoo 18 - Odoo Slides
Form View Attributes in Odoo 18 - Odoo Slides
Celine George
 
Myopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduateMyopathies (muscle disorders) for undergraduate
Myopathies (muscle disorders) for undergraduate
Mohamed Rizk Khodair
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Botany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic ExcellenceBotany Assignment Help Guide - Academic Excellence
Botany Assignment Help Guide - Academic Excellence
online college homework help
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
Ancient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian HistoryAncient Stone Sculptures of India: As a Source of Indian History
Ancient Stone Sculptures of India: As a Source of Indian History
Virag Sontakke
 
CNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscessCNS infections (encephalitis, meningitis & Brain abscess
CNS infections (encephalitis, meningitis & Brain abscess
Mohamed Rizk Khodair
 
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
 
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon DolabaniHistory Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
History Of The Monastery Of Mor Gabriel Philoxenos Yuhanon Dolabani
fruinkamel7m
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
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
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)spinal cord disorders (Myelopathies and radiculoapthies)
spinal cord disorders (Myelopathies and radiculoapthies)
Mohamed Rizk Khodair
 
Rock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian HistoryRock Art As a Source of Ancient Indian History
Rock Art As a Source of Ancient Indian History
Virag Sontakke
 
Chemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptxChemotherapy of Malignancy -Anticancer.pptx
Chemotherapy of Malignancy -Anticancer.pptx
Mayuri Chavan
 
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
 
Ad

In the given example only one object will be created. Firstly JVM will not find any string object with the value “Welcome” in the string

  • 2. Outline ▪ What is string ? ▪ How to createString object? ▪ Some important operations of strings ▪ Some important string class methods ▪ StringBuffer class & StringBuilder class ▪ Difference between String andStringBuffer ▪ Difference between StringBuffer andStringBuilder
  • 3. What is String ? ▪ Strings, which are widely used in Java programming, are a sequence of characters. In Java programming language, strings are treated as objects. ▪ The Java platform provides the String class to create and manipulate strings.
  • 4. Important Notes about String ▪ String – Object or Primitive? - Strings could be considered a primitive type in Java, but in fact they are not. As a String is actually made up of an array of char primitives. ▪ String objects are immutable! -That means once a string object is created it cannot be altered. For mutable string, you can use StringBuffer and StringBuilder classes. [An object whose state cannot be changed after it is created is known as an Immutable object. String, Integer, Byte, Short, Float, Double and all other wrapper class's objects are immutable.]
  • 5. How to createString object? There are two ways to createString object: 1.By string literal For Example: String s="welcome"; 2.By new keyword For Example: String s=newString("Welcome");
  • 6. Java String Example Output : java strings example
  • 7. Some important operations of strings ▪ StringConcatenation ▪ StringComparison ▪ Substring ▪ Length ofString etc.
  • 8. String Concatenation ▪ There are 2 methods to concatenate two or more string. Concatenate two or more string. Using concat() method Using + operator
  • 9. String Comparison ▪ String comparison can be done in 3 ways. String Comparison Using equals() method Using == operator By CompareTo() method
  • 11. Substring in Java ▪ A part of string is called substring. In other words, substring is a subset of another string. ▪ We can get substring from the given string object by one of the two methods: 1. publicString substring(int startIndex): 2. publicString substring(int startIndex, int endIndex):
  • 12. Length of String finds the length of the string. It returns count of total ▪ The java string length() method number of characters.
  • 13. Some more string class methods ▪ The java.lang.String class provides a lot of methods to work on string. By the help of these methods, we can perform operations on strings. ▪ Here we will learn about the following methods : 1. charAt() 2. contains() 3. getChars() 4. indexOf() 5. replace() 6. toCharArray() 7. toLowerCase() 8. toUpperCase()
  • 14. charAt() & contains()  charAt() = returns a char value at the given index number.The index number starts from 0.  contains() = searches the sequence of characters in this string. It returns true if sequence of char values are found in this string otherwise returns false.
  • 15. getChars()  getChars() = copies the content of this string into specified char array.There are 4 arguments passed in getChars() method. It throws StringIndexOutOfBoundsException if beginIndex is greater than endIndex.
  • 16. indexOf()  indexOf() = returns index of given character value or substring. If it is not found, it returns -1. The index counter starts from zero.
  • 17. replace()  replace() = returns a string replacing all the old char orCharSequence to new char or CharSequence.
  • 18. toCharArray()  toCharArray() = converts this string into character array.
  • 19. toLowerCase() & toUpperCase()  toLowerCase() = returns the string in lowercase letter. In other words, it converts all characters of the string into lower case letter.  toUpperCase() =returns the string in uppercase letter. In other words, it converts all characters of the string into upper case letter.
  • 20. Java StringBuffer class ▪ Java StringBuffer class is used to created mutable (modifiable) string. ▪ ImportantConstructors of StringBuffer class:  StringBuffer(): creates an empty string buffer with the initial capacity of 16.  StringBuffer(String str): creates a string buffer with the specified string.  StringBuffer(int capacity): creates an empty string buffer with the specified capacity as length. ▪ Important methods of StringBuffer class:  append(String s): is used to append the specified string with this string.The append() method is overloaded like append(char), append(boolean), append(int), append(float), append(double) etc.  insert(int offset, String s): is used to insert the specified string with this string at the specified position. The insert() method is overloaded like insert(int, char), insert(int, boolean), insert(int, int), insert(int, float), insert(int, double) etc.  replace(int startIndex, int endIndex,String str): is used to replace the string from specified startIndex and endIndex.  delete(int startIndex, int endIndex): is used to delete the string from specified startIndex and endIndex.  reverse(): is used to reverse the string.  capacity(): is used to return the current capacity.
  • 21. Java StringBuilder class ▪ Java StringBuilder class is used to create mutable (modifiable) string.TheJavaStringBuilder class is same as StringBuffer class except that it is non-synchronized.
  • 22. Example of using StringBuffer & StringBuilder class
  • 23. Difference between String and StringBuffer No. String StringBuffer 1) String class is immutable. StringBuffer class is mutable. 2) String is slow and consumes more memory when you concat too many strings because every time it creates new instance. StringBuffer is fast and consumes less memory when you cancat strings. 3) String class overrides the equals() method of Object class. So you can compare the contents of two strings by equals() method. StringBuffer class doesn't override the equals() method of Object class.
  • 24. Difference between StringBuffer and StringBuilder 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 thanStringBuilder. StringBuilder StringBuffer. is more efficient than
  翻译: