SlideShare a Scribd company logo
1 of 15
Download to read offline
String
Presented by Raj
Under the guidance of sunny
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.
it introduces in JDK1.1
How to Create a String Object?
String object can be created using two ways:
String Literal.
new keyword.
1) By String Literal.
Java String literal can be created and represented using
the double-quotes.
All of the content/characters can be added in between
the double quotes.
public class Main {
public static void main(String args[]) {
String Str1 = "Java";
String Str2 = “Java”;
}
}
The string literal is always created in the string
constant pool.
In Java, String constant pool is a special area
that is used for storing string objects.
public class Main {
public static void main(String args[]) {
String Str1 = "Java";
String Str2 = “Java”;
String str3 = “Python”;
}
}
2) By New Keyword.
string is created with new, a new object of the String
class is created in the heap memory, outside the string
constant pool.
Syntax:
String stringName = new String("string_value");
Example:
String str = new String("Program");
System.out.println(str); //Program
Example 1
public class Main{
public static void main(String[] args) {
String str1 = "java";
String str2 = "programming";
System.out.println(str1.length()); // 4
String str4 = str1.concat(str2);
System.out.println(str4); // javaprogramming
}
}
== operator vs equals()
String str1 = "java";
String str2 = new String("java");
if(str1 == str2){
System.out.println("both string are equal");
} else{
System.out.println("both string are not equal");
}
if(str1.equals(str2)){
System.out.println("both string are equal");
} else{
System.out.println("both string are not equal");
}
equals() vs equalIgnorecase()
String str1 = "java";
String str2 = new String("Java");
if(str1.equals(str2)){
System.out.println("both string are equal");
} else{
System.out.println("both string are not equal");
}
if(str1.equalsIgnoreCase(str2)){
System.out.println("both string are equal");
} else{
System.out.println("both string are not equal");
}
StringBuffer is mutable String
StringBuffer Class is (synchronized) thread safe
it is safe and will result in an order
What is String Buffer?
Example
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
What is String Builder?
StringBuffer Class StringBuilder Class
StringBuffer is present in Java. StringBuilder was introduced in Java 5.
StringBuffer is synchronized. StringBuilder is asynchronized.
Due to synchronization, StringBuffer is called a
thread safe class.
Due to its asynchronous nature, StringBuilder is
not a thread safe class.
Due to synchronization, StringBuffer is lot slower
than StringBuilder.
Since there is no preliminary check for multiple
threads, StringBuilder is a lot faster than
StringBuffer.
String Buffer vs string Builder
Thank
You

More Related Content

Similar to Java Presentation on the topic of string

Java - Strings Concepts
Java - Strings ConceptsJava - Strings Concepts
Java - Strings ConceptsVicter Paul
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20myrajendra
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................suchitrapoojari984
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processingmaznabili
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packagesSardar Alam
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction AKR Education
 
javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string classfedcoordinator
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java conceptsChikugehlot
 

Similar to Java Presentation on the topic of string (20)

Java - Strings Concepts
Java - Strings ConceptsJava - Strings Concepts
Java - Strings Concepts
 
Java_PPT.pptx
Java_PPT.pptxJava_PPT.pptx
Java_PPT.pptx
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
String classes and its methods.20
String classes and its methods.20String classes and its methods.20
String classes and its methods.20
 
Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................Unit-2.Arrays and Strings.pptx.................
Unit-2.Arrays and Strings.pptx.................
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
 
Java Programming
Java ProgrammingJava Programming
Java Programming
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
 
Strings in Java
Strings in JavaStrings in Java
Strings in Java
 
Java Unit 2(Part 1)
Java Unit 2(Part 1)Java Unit 2(Part 1)
Java Unit 2(Part 1)
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
 
Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction Unit 1 of java part 2 basic introduction
Unit 1 of java part 2 basic introduction
 
javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
 
Java String
Java StringJava String
Java String
 
CHAPTER 3 part2.pdf
CHAPTER 3 part2.pdfCHAPTER 3 part2.pdf
CHAPTER 3 part2.pdf
 
CAP615-Unit1.pptx
CAP615-Unit1.pptxCAP615-Unit1.pptx
CAP615-Unit1.pptx
 
Arrays
ArraysArrays
Arrays
 
Core java concepts
Core    java  conceptsCore    java  concepts
Core java concepts
 

Recently uploaded

Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxsiddharthjain2303
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxVelmuruganTECE
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionDr.Costas Sachpazis
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleAlluxio, Inc.
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfAsst.prof M.Gokilavani
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptJasonTagapanGulla
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm Systemirfanmechengr
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfROCENODodongVILLACER
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptMadan Karki
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONjhunlian
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncssuser2ae721
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptNarmatha D
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...VICTOR MAESTRE RAMIREZ
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxRomil Mishra
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfRajuKanojiya4
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort servicejennyeacort
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substationstephanwindworld
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptxNikhil Raut
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating SystemRashmi Bhat
 

Recently uploaded (20)

Energy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptxEnergy Awareness training ppt for manufacturing process.pptx
Energy Awareness training ppt for manufacturing process.pptx
 
Internet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptxInternet of things -Arshdeep Bahga .pptx
Internet of things -Arshdeep Bahga .pptx
 
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective IntroductionSachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
Sachpazis Costas: Geotechnical Engineering: A student's Perspective Introduction
 
Correctly Loading Incremental Data at Scale
Correctly Loading Incremental Data at ScaleCorrectly Loading Incremental Data at Scale
Correctly Loading Incremental Data at Scale
 
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdfCCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
CCS355 Neural Networks & Deep Learning Unit 1 PDF notes with Question bank .pdf
 
Solving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.pptSolving The Right Triangles PowerPoint 2.ppt
Solving The Right Triangles PowerPoint 2.ppt
 
Class 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm SystemClass 1 | NFPA 72 | Overview Fire Alarm System
Class 1 | NFPA 72 | Overview Fire Alarm System
 
Risk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdfRisk Assessment For Installation of Drainage Pipes.pdf
Risk Assessment For Installation of Drainage Pipes.pdf
 
Indian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.pptIndian Dairy Industry Present Status and.ppt
Indian Dairy Industry Present Status and.ppt
 
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTIONTHE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
THE SENDAI FRAMEWORK FOR DISASTER RISK REDUCTION
 
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsyncWhy does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
Why does (not) Kafka need fsync: Eliminating tail latency spikes caused by fsync
 
Industrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.pptIndustrial Safety Unit-IV workplace health and safety.ppt
Industrial Safety Unit-IV workplace health and safety.ppt
 
Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...Software and Systems Engineering Standards: Verification and Validation of Sy...
Software and Systems Engineering Standards: Verification and Validation of Sy...
 
Mine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptxMine Environment II Lab_MI10448MI__________.pptx
Mine Environment II Lab_MI10448MI__________.pptx
 
National Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdfNational Level Hackathon Participation Certificate.pdf
National Level Hackathon Participation Certificate.pdf
 
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort serviceGurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
Gurgaon ✡️9711147426✨Call In girls Gurgaon Sector 51 escort service
 
Earthing details of Electrical Substation
Earthing details of Electrical SubstationEarthing details of Electrical Substation
Earthing details of Electrical Substation
 
Steel Structures - Building technology.pptx
Steel Structures - Building technology.pptxSteel Structures - Building technology.pptx
Steel Structures - Building technology.pptx
 
Input Output Management in Operating System
Input Output Management in Operating SystemInput Output Management in Operating System
Input Output Management in Operating System
 
Design and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdfDesign and analysis of solar grass cutter.pdf
Design and analysis of solar grass cutter.pdf
 

Java Presentation on the topic of string

  • 1. String Presented by Raj Under the guidance of sunny
  • 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. it introduces in JDK1.1
  • 3. How to Create a String Object? String object can be created using two ways: String Literal. new keyword. 1) By String Literal. Java String literal can be created and represented using the double-quotes. All of the content/characters can be added in between the double quotes.
  • 4. public class Main { public static void main(String args[]) { String Str1 = "Java"; String Str2 = “Java”; } } The string literal is always created in the string constant pool. In Java, String constant pool is a special area that is used for storing string objects.
  • 5. public class Main { public static void main(String args[]) { String Str1 = "Java"; String Str2 = “Java”; String str3 = “Python”; } }
  • 6. 2) By New Keyword. string is created with new, a new object of the String class is created in the heap memory, outside the string constant pool. Syntax: String stringName = new String("string_value"); Example: String str = new String("Program"); System.out.println(str); //Program
  • 7.
  • 8. Example 1 public class Main{ public static void main(String[] args) { String str1 = "java"; String str2 = "programming"; System.out.println(str1.length()); // 4 String str4 = str1.concat(str2); System.out.println(str4); // javaprogramming } }
  • 9. == operator vs equals() String str1 = "java"; String str2 = new String("java"); if(str1 == str2){ System.out.println("both string are equal"); } else{ System.out.println("both string are not equal"); } if(str1.equals(str2)){ System.out.println("both string are equal"); } else{ System.out.println("both string are not equal"); }
  • 10. equals() vs equalIgnorecase() String str1 = "java"; String str2 = new String("Java"); if(str1.equals(str2)){ System.out.println("both string are equal"); } else{ System.out.println("both string are not equal"); } if(str1.equalsIgnoreCase(str2)){ System.out.println("both string are equal"); } else{ System.out.println("both string are not equal"); }
  • 11. StringBuffer is mutable String StringBuffer Class is (synchronized) thread safe it is safe and will result in an order What is String Buffer?
  • 13. 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 What is String Builder?
  • 14. StringBuffer Class StringBuilder Class StringBuffer is present in Java. StringBuilder was introduced in Java 5. StringBuffer is synchronized. StringBuilder is asynchronized. Due to synchronization, StringBuffer is called a thread safe class. Due to its asynchronous nature, StringBuilder is not a thread safe class. Due to synchronization, StringBuffer is lot slower than StringBuilder. Since there is no preliminary check for multiple threads, StringBuilder is a lot faster than StringBuffer. String Buffer vs string Builder