SlideShare a Scribd company logo
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Beginners | Edureka
Java String Creating a String Hands On
String Pool String Methods
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java String
Object 01
String is a Java
object
Characters 02
Class 03
Immutable 04
Represents a sequence
of characters
java.lang.String class is used to
create and manipulate strings
A string is immutable
in nature
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy dog
The quick fox jumps The quick lazy dog
Java Strings
The quick brown fox jumps over the lazy dogSearch
Create Substring
Create new strings The quick brown fox jumps over the lazy dog
With Strings in Java you can perform various operations, some of which are:
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings
java.lang.String
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Java Strings
java.lang.String
ComparableSerializable CharSequence
public final class String
extends Object
implements Serializable, Comparable<String>, CharSequence
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Comparable interface is used for ordering the objects of any user-defined class. This interface is
found in java.lang.package and contains only one method named compareTo(Object)
A CharSequence interface is a readable sequence of characters. This interface provides uniform,
read-only access to various kind of character sequences
Serializable is a marker interface that contains no data member or method. It is used to “mark”
the java classes so that objects of these classes may get a specific capability
Java Strings
Comparable
Serializable
CharSequence
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
java,lang.StringBuffer is a peer class
of String that represents growable and
writable character sequences
java.lang.StringBuilder is identical to
StringBuffer except for one important
difference that it is not synchronized, which
means it is not thread safe
java.lang.String class is used to create string
objects and provides a list of methods to
create and manipulate Strings
Java Strings
CharSequence
String StringBuffer StringBuilder
String Pool
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
String Pool
Java String pool refers to collection of Strings which
are stored in heap memory
As String objects are immutable in nature the
concept of String Pool came into the picture
String Pool helps in saving space for Java Runtime
Heap Memory
String Pool
Literal
new
Keyword
Creating a String
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Literal
new
Keyword
Creating a String – Using Literal
Java String literal is created by using double quotes
String str = “Edureka”;
Heap Memory
String Pool
Edureka
str
str1
String str2 = “Welcome”;str2
Welcome String str1 = “Edureka”;
Before creating a String literal first looks for String with same value in the String pool, if found it
returns the reference else it creates a new String in the pool & returns the reference
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
Literal
new
Keyword
Creating a String – Using new Keyword
Heap Memory
String Pool
Edureka
Welcome
str
str1
str2
Edureka str3
String object created using “new” keyword it always create a new object in heap memory
String str = new String (“Edureka”);
String Methods
JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training
String Methods
boolean equals(Object another) Checks the equality of string with the given object
equalsIgnoreCase() Compares another string without matching the case
length() Returns a strings length
charAt(i) Returns a character at a index ‘i’
toUpperCase() Returns the string in uppercase
toLowerCase() Returns the string in lowercase
replace(oldVal, newVal) Replaces all occurrences of the specified char value with the given value
trim() Removes the white spaces from the beginning and ending of string
contains("value") Checks for the matching sequence of char value and returns true/false
toCharArray() Converts a string to a new character array
IsEmpty() Checks whether the string is empty or not
endsWith() Checks if the string ends with the specified suffix
concat() Concatenates two strings
Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Beginners | Edureka

More Related Content

PPT
Java Collections Framework
Sony India Software Center
 
PDF
Arrays in Java
Naz Abdalla
 
PPSX
Collections - Lists, Sets
Hitesh-Java
 
PDF
Java Collection framework
ankitgarg_er
 
PDF
07 java collection
Abhishek Khune
 
PPTX
Strings in Java
Abhilash Nair
 
ODP
Java Collections
parag
 
Java Collections Framework
Sony India Software Center
 
Arrays in Java
Naz Abdalla
 
Collections - Lists, Sets
Hitesh-Java
 
Java Collection framework
ankitgarg_er
 
07 java collection
Abhishek Khune
 
Strings in Java
Abhilash Nair
 
Java Collections
parag
 

What's hot (20)

PPTX
6. static keyword
Indu Sharma Bhardwaj
 
PDF
Collections In Java
Binoj T E
 
PDF
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Edureka!
 
PPTX
Java - Collections framework
Riccardo Cardin
 
PPT
Collection Framework in java
CPD INDIA
 
PDF
Java 8 Lambda Expressions & Streams
NewCircle Training
 
PPTX
MULTI THREADING IN JAVA
VINOTH R
 
PDF
Java collections
Hamid Ghorbani
 
PPTX
Constructor in java
Hitesh Kumar
 
PPTX
Java Strings
RaBiya Chaudhry
 
PPT
Java collection
Arati Gadgil
 
PPT
Java Presentation
pm2214
 
PDF
5 collection framework
Minal Maniar
 
PPT
Abstract class in java
Lovely Professional University
 
PPTX
Packages in java
Kavitha713564
 
PPTX
Interface in java
Kavitha713564
 
PPTX
This keyword in java
Hitesh Kumar
 
PPTX
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
PPT
Oops concepts in php
CPD INDIA
 
PDF
Java I/O
Jussi Pohjolainen
 
6. static keyword
Indu Sharma Bhardwaj
 
Collections In Java
Binoj T E
 
Java Classes | Java Tutorial for Beginners | Java Classes and Objects | Java ...
Edureka!
 
Java - Collections framework
Riccardo Cardin
 
Collection Framework in java
CPD INDIA
 
Java 8 Lambda Expressions & Streams
NewCircle Training
 
MULTI THREADING IN JAVA
VINOTH R
 
Java collections
Hamid Ghorbani
 
Constructor in java
Hitesh Kumar
 
Java Strings
RaBiya Chaudhry
 
Java collection
Arati Gadgil
 
Java Presentation
pm2214
 
5 collection framework
Minal Maniar
 
Abstract class in java
Lovely Professional University
 
Packages in java
Kavitha713564
 
Interface in java
Kavitha713564
 
This keyword in java
Hitesh Kumar
 
Design Pattern - Factory Method Pattern
Mudasir Qazi
 
Oops concepts in php
CPD INDIA
 
Ad

Similar to Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Beginners | Edureka (20)

PDF
Java String
Java2Blog
 
PPTX
String in java
Ideal Eyes Business College
 
PPTX
Java Strings.pptxJava Strings.pptxJava Strings.pptx
Shivam287777
 
PPTX
What is String in Java?
RAKESH P
 
PDF
Java - Strings Concepts
Victer Paul
 
PPTX
Day_5.1.pptx
ishasharma835109
 
PDF
Lecture 7
Debasish Pratihari
 
DOCX
Java67
Nagesh Halgonde
 
PPT
String Handling
Bharat17485
 
DOCX
Java interview questions and answers for cognizant By Data Council Pune
Pankaj kshirsagar
 
PPT
Core_java_ppt.ppt
SHIBDASDUTTA
 
PPTX
Java String
SATYAM SHRIVASTAV
 
PPTX
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PriyanshuGupta101797
 
PDF
Java Interview Questions PDF By ScholarHat
Scholarhat
 
PPTX
OCA Java SE 8 Exam Chapter 3 Core Java APIs
İbrahim Kürce
 
PDF
Java R20 - UNIT-5.pdf
Pamarthi Kumar
 
PPTX
Session 05 - Strings in Java
PawanMM
 
PPT
09slide
Dorothea Chaffin
 
PPT
JavaYDL9
Terry Yoast
 
Java String
Java2Blog
 
Java Strings.pptxJava Strings.pptxJava Strings.pptx
Shivam287777
 
What is String in Java?
RAKESH P
 
Java - Strings Concepts
Victer Paul
 
Day_5.1.pptx
ishasharma835109
 
String Handling
Bharat17485
 
Java interview questions and answers for cognizant By Data Council Pune
Pankaj kshirsagar
 
Core_java_ppt.ppt
SHIBDASDUTTA
 
Java String
SATYAM SHRIVASTAV
 
JAVA AND OOPS CONCEPTS.pptx helpful for engineering
PriyanshuGupta101797
 
Java Interview Questions PDF By ScholarHat
Scholarhat
 
OCA Java SE 8 Exam Chapter 3 Core Java APIs
İbrahim Kürce
 
Java R20 - UNIT-5.pdf
Pamarthi Kumar
 
Session 05 - Strings in Java
PawanMM
 
JavaYDL9
Terry Yoast
 
Ad

More from Edureka! (20)

PDF
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
PDF
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
PDF
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
PDF
Tableau Tutorial for Data Science | Edureka
Edureka!
 
PDF
Python Programming Tutorial | Edureka
Edureka!
 
PDF
Top 5 PMP Certifications | Edureka
Edureka!
 
PDF
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
PDF
Linux Mint Tutorial | Edureka
Edureka!
 
PDF
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
PDF
Importance of Digital Marketing | Edureka
Edureka!
 
PDF
RPA in 2020 | Edureka
Edureka!
 
PDF
Email Notifications in Jenkins | Edureka
Edureka!
 
PDF
EA Algorithm in Machine Learning | Edureka
Edureka!
 
PDF
Cognitive AI Tutorial | Edureka
Edureka!
 
PDF
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
PDF
Blue Prism Top Interview Questions | Edureka
Edureka!
 
PDF
Big Data on AWS Tutorial | Edureka
Edureka!
 
PDF
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
PDF
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
PDF
Introduction to DevOps | Edureka
Edureka!
 
What to learn during the 21 days Lockdown | Edureka
Edureka!
 
Top 10 Dying Programming Languages in 2020 | Edureka
Edureka!
 
Top 5 Trending Business Intelligence Tools | Edureka
Edureka!
 
Tableau Tutorial for Data Science | Edureka
Edureka!
 
Python Programming Tutorial | Edureka
Edureka!
 
Top 5 PMP Certifications | Edureka
Edureka!
 
Top Maven Interview Questions in 2020 | Edureka
Edureka!
 
Linux Mint Tutorial | Edureka
Edureka!
 
How to Deploy Java Web App in AWS| Edureka
Edureka!
 
Importance of Digital Marketing | Edureka
Edureka!
 
RPA in 2020 | Edureka
Edureka!
 
Email Notifications in Jenkins | Edureka
Edureka!
 
EA Algorithm in Machine Learning | Edureka
Edureka!
 
Cognitive AI Tutorial | Edureka
Edureka!
 
AWS Cloud Practitioner Tutorial | Edureka
Edureka!
 
Blue Prism Top Interview Questions | Edureka
Edureka!
 
Big Data on AWS Tutorial | Edureka
Edureka!
 
A star algorithm | A* Algorithm in Artificial Intelligence | Edureka
Edureka!
 
Kubernetes Installation on Ubuntu | Edureka
Edureka!
 
Introduction to DevOps | Edureka
Edureka!
 

Recently uploaded (20)

PDF
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
PPTX
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
PDF
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
PDF
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
PDF
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
PDF
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
PDF
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
PDF
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
PDF
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
PDF
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
DOCX
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
PDF
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
PDF
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
PDF
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
PDF
DevOps & Developer Experience Summer BBQ
AUGNYC
 
PDF
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
PPTX
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
PDF
Software Development Methodologies in 2025
KodekX
 
PDF
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 
madgavkar20181017ppt McKinsey Presentation.pdf
georgschmitzdoerner
 
C Programming Basics concept krnppt.pptx
Karan Prajapat
 
Google’s NotebookLM Unveils Video Overviews
SOFTTECHHUB
 
How-Cloud-Computing-Impacts-Businesses-in-2025-and-Beyond.pdf
Artjoker Software Development Company
 
Revolutionize Operations with Intelligent IoT Monitoring and Control
Rejig Digital
 
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Francisco Vieira Júnior
 
NewMind AI Monthly Chronicles - July 2025
NewMind AI
 
SparkLabs Primer on Artificial Intelligence 2025
SparkLabs Group
 
Test Bank, Solutions for Java How to Program, An Objects-Natural Approach, 12...
famaw19526
 
Using Anchore and DefectDojo to Stand Up Your DevSecOps Function
Anchore
 
Unlocking the Future- AI Agents Meet Oracle Database 23ai - AIOUG Yatra 2025.pdf
Sandesh Rao
 
Top AI API Alternatives to OpenAI: A Side-by-Side Breakdown
vilush
 
Event Presentation Google Cloud Next Extended 2025
minhtrietgect
 
Security features in Dell, HP, and Lenovo PC systems: A research-based compar...
Principled Technologies
 
NewMind AI Weekly Chronicles - July'25 - Week IV
NewMind AI
 
DevOps & Developer Experience Summer BBQ
AUGNYC
 
BLW VOCATIONAL TRAINING SUMMER INTERNSHIP REPORT
codernjn73
 
The Power of IoT Sensor Integration in Smart Infrastructure and Automation.pptx
Rejig Digital
 
Software Development Methodologies in 2025
KodekX
 
Building High-Performance Oracle Teams: Strategic Staffing for Database Manag...
SMACT Works
 

Java Strings Tutorial | String Manipulation in Java | Java Tutorial For Beginners | Edureka

  • 2. Java String Creating a String Hands On String Pool String Methods
  • 3. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java String Object 01 String is a Java object Characters 02 Class 03 Immutable 04 Represents a sequence of characters java.lang.String class is used to create and manipulate strings A string is immutable in nature
  • 4. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training The quick brown fox jumps over the lazy dogThe quick brown fox jumps over the lazy dog The quick fox jumps The quick lazy dog Java Strings The quick brown fox jumps over the lazy dogSearch Create Substring Create new strings The quick brown fox jumps over the lazy dog With Strings in Java you can perform various operations, some of which are:
  • 5. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Strings java.lang.String
  • 6. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Java Strings java.lang.String ComparableSerializable CharSequence public final class String extends Object implements Serializable, Comparable<String>, CharSequence
  • 7. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Comparable interface is used for ordering the objects of any user-defined class. This interface is found in java.lang.package and contains only one method named compareTo(Object) A CharSequence interface is a readable sequence of characters. This interface provides uniform, read-only access to various kind of character sequences Serializable is a marker interface that contains no data member or method. It is used to “mark” the java classes so that objects of these classes may get a specific capability Java Strings Comparable Serializable CharSequence
  • 8. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training java,lang.StringBuffer is a peer class of String that represents growable and writable character sequences java.lang.StringBuilder is identical to StringBuffer except for one important difference that it is not synchronized, which means it is not thread safe java.lang.String class is used to create string objects and provides a list of methods to create and manipulate Strings Java Strings CharSequence String StringBuffer StringBuilder
  • 10. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training String Pool Java String pool refers to collection of Strings which are stored in heap memory As String objects are immutable in nature the concept of String Pool came into the picture String Pool helps in saving space for Java Runtime Heap Memory String Pool
  • 12. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Literal new Keyword Creating a String – Using Literal Java String literal is created by using double quotes String str = “Edureka”; Heap Memory String Pool Edureka str str1 String str2 = “Welcome”;str2 Welcome String str1 = “Edureka”; Before creating a String literal first looks for String with same value in the String pool, if found it returns the reference else it creates a new String in the pool & returns the reference
  • 13. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training Literal new Keyword Creating a String – Using new Keyword Heap Memory String Pool Edureka Welcome str str1 str2 Edureka str3 String object created using “new” keyword it always create a new object in heap memory String str = new String (“Edureka”);
  • 15. JAVA CERTIFICATION TRAINING www.edureka.co/java-j2ee-soa-training String Methods boolean equals(Object another) Checks the equality of string with the given object equalsIgnoreCase() Compares another string without matching the case length() Returns a strings length charAt(i) Returns a character at a index ‘i’ toUpperCase() Returns the string in uppercase toLowerCase() Returns the string in lowercase replace(oldVal, newVal) Replaces all occurrences of the specified char value with the given value trim() Removes the white spaces from the beginning and ending of string contains("value") Checks for the matching sequence of char value and returns true/false toCharArray() Converts a string to a new character array IsEmpty() Checks whether the string is empty or not endsWith() Checks if the string ends with the specified suffix concat() Concatenates two strings