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

PPTX
Introduction to Spring Framework
PPTX
Java database connectivity with MySql
PDF
Methods in Java
PDF
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
PPTX
Introduction to Spring Boot
PPTX
Spring Framework
PPT
Exception Handling in JAVA
PDF
Java Collection framework
Introduction to Spring Framework
Java database connectivity with MySql
Methods in Java
Java Collections | Collections Framework in Java | Java Tutorial For Beginner...
Introduction to Spring Boot
Spring Framework
Exception Handling in JAVA
Java Collection framework

What's hot (20)

PPTX
Polymorphism presentation in java
PDF
REST APIs with Spring
PDF
Generics
PPTX
Java RMI
PPT
Java servlet life cycle - methods ppt
PPTX
Spring boot
PPT
Java Persistence API (JPA) Step By Step
PPTX
Modern JS with ES6
PDF
Getting started with Spring Security
PPTX
PHP FUNCTIONS
PDF
Nodejs presentation
PPT
Java And Multithreading
PPTX
Core java complete ppt(note)
PDF
Spring Security
PPSX
Collections - Lists, Sets
PPSX
PPT
Php with MYSQL Database
PPTX
Intro to React
PPTX
Asp.Net Core MVC with Entity Framework
Polymorphism presentation in java
REST APIs with Spring
Generics
Java RMI
Java servlet life cycle - methods ppt
Spring boot
Java Persistence API (JPA) Step By Step
Modern JS with ES6
Getting started with Spring Security
PHP FUNCTIONS
Nodejs presentation
Java And Multithreading
Core java complete ppt(note)
Spring Security
Collections - Lists, Sets
Php with MYSQL Database
Intro to React
Asp.Net Core MVC with Entity Framework
Ad

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

PPTX
Java Strings.pptxJava Strings.pptxJava Strings.pptx
PPTX
Day_5.1.pptx
PPTX
PPTX
What is String in Java?
PDF
Java Presentation on the topic of string
PPTX
More about java strings - Immutability and String Pool
PPTX
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
PDF
Java - Strings Concepts
PPT
Strings in javamnjn ijnjun oinoin oinoi .ppt
PDF
PPT
Text processing
PPT
Java™ (OOP) - Chapter 9: "Strings and Text I/O"
DOCX
Java R20 - UNIT-5.docx
PDF
Java R20 - UNIT-5.pdf
PPT
String Handling
PPTX
Java Strings - using Strings in practice
PPTX
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
PPTX
Introduction to Java Strings, By Kavita Ganesan
PPT
8. String
Java Strings.pptxJava Strings.pptxJava Strings.pptx
Day_5.1.pptx
What is String in Java?
Java Presentation on the topic of string
More about java strings - Immutability and String Pool
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
Java - Strings Concepts
Strings in javamnjn ijnjun oinoin oinoi .ppt
Text processing
Java™ (OOP) - Chapter 9: "Strings and Text I/O"
Java R20 - UNIT-5.docx
Java R20 - UNIT-5.pdf
String Handling
Java Strings - using Strings in practice
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
Introduction to Java Strings, By Kavita Ganesan
8. String
Ad

More from Edureka! (20)

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

Recently uploaded (20)

PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PDF
Agricultural_Statistics_at_a_Glance_2022_0.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Tartificialntelligence_presentation.pptx
PDF
cuic standard and advanced reporting.pdf
PDF
A comparative analysis of optical character recognition models for extracting...
PPTX
Spectroscopy.pptx food analysis technology
PDF
Building Integrated photovoltaic BIPV_UPV.pdf
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Encapsulation_ Review paper, used for researhc scholars
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PDF
Approach and Philosophy of On baking technology
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Agricultural_Statistics_at_a_Glance_2022_0.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
gpt5_lecture_notes_comprehensive_20250812015547.pdf
1. Introduction to Computer Programming.pptx
Tartificialntelligence_presentation.pptx
cuic standard and advanced reporting.pdf
A comparative analysis of optical character recognition models for extracting...
Spectroscopy.pptx food analysis technology
Building Integrated photovoltaic BIPV_UPV.pdf
MIND Revenue Release Quarter 2 2025 Press Release
20250228 LYD VKU AI Blended-Learning.pptx
Encapsulation_ Review paper, used for researhc scholars
Network Security Unit 5.pdf for BCA BBA.
SOPHOS-XG Firewall Administrator PPT.pptx
Reach Out and Touch Someone: Haptics and Empathic Computing
Per capita expenditure prediction using model stacking based on satellite ima...
Group 1 Presentation -Planning and Decision Making .pptx
Approach and Philosophy of On baking technology

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