SlideShare a Scribd company logo
5
String Declaration
String Declaration: The most direct way to create a
string is as follows;
String greeting = "Hello world!";//String literal
Other Common Declarations:
String helloString = new String(helloArray);
char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
Most read
8
Methods of String(Cont…)
Concatenating Strings:One String can be
concatenated to another string.This will produce
a new string object joining two strings.
Strings are more commonly concatenated with the
+ operator and concat method.
Syntax:
string1.concat(string2);
string1+string2
Most read
10
 String toString()
This object (which is already a string!) is itself returned.
 String toUpperCase()
Converts all of the characters in this String to upper case
using the rules of the default locale.
 String trim()
Returns a copy of the string, with leading and trailing
whitespace omitted.
 boolean startsWith(String prefix)
Tests if this string starts with the specified prefix.
 boolean contentEquals(StringBuffer sb)
Returns true if and only if this String represents the same
sequence of characters as the specified StringBuffer.
Methods of String(Cont…)
Most read
Java Strings  methods and operations.ppt
● This module introduces the participants to the string
object.
● Importance of String Objects and How to create them.
● Varioius Constructors that are available to create
Strings.
● Working with methods that are available with strings.
● Understanding Necessity of StringBuffer class.
● Working with methods of StringBuffer class.
● Introduction to StringBuilder class.
● Working with methods of StringBuilder class.
Module Overview
2
 Uderstand the concept of Strings and create string
objects.
 Understand advantages and disadvantages of Strings.
 Declare and create Strings using different types of
constructors.
 Working with Strings and its different types of
methods.
 Determine the usage of String Buffer and
StringBuilder.
Objectives
3
String: Strings are a sequence of characters, which are
implemented as objects.
Charecteristics of Strings:
• The String class is immutable,meaning once created
a String object cannot be changed.
• If any modifications is done to the existing string
object a new object is created internally.
• String objects are created by using the new keyword
and a constructor. The String class has eleven
constructors that allow you to provide the initial
value of the string using different sources, such as an
array of characters.
String
4
String Declaration
String Declaration: The most direct way to create a
string is as follows;
String greeting = "Hello world!";//String literal
Other Common Declarations:
String helloString = new String(helloArray);
char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
Example of String Class.
public class StringDemo{
public static void main(String args[]){
char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
String helloString = new String(helloArray);
String helloString2 = new String(“hello!!!”);
System.out.println( helloString );
}
}
Output:hello.
Methods Of String
 Accessor:Methods used to obtain information
about an object are known as accessor methods.
One accessor method that you can use with
strings is the length() method, which returns the
number of characters contained in the string
object.
Syntax:
<StringOBject>.length();
Example:
String name = “java”;
int length = name.length();
Methods of String(Cont…)
Concatenating Strings:One String can be
concatenated to another string.This will produce
a new string object joining two strings.
Strings are more commonly concatenated with the
+ operator and concat method.
Syntax:
string1.concat(string2);
string1+string2
Methods of String(Cont…)
 String substring(int beginIndex)
Returns a new string that is a substring of this string.
 char[] toCharArray()
Converts this string to a new character array.
 String toLowerCase()
Converts all of the characters in this String to lower
case using the rules of the default locale.
 String replace(char oldChar, char newChar)
Returns a new string resulting from replacing all
occurrences of oldChar in this string with newChar.
 String[] split(String regex)
Splits this string around matches of the given regular
expression.
 String toString()
This object (which is already a string!) is itself returned.
 String toUpperCase()
Converts all of the characters in this String to upper case
using the rules of the default locale.
 String trim()
Returns a copy of the string, with leading and trailing
whitespace omitted.
 boolean startsWith(String prefix)
Tests if this string starts with the specified prefix.
 boolean contentEquals(StringBuffer sb)
Returns true if and only if this String represents the same
sequence of characters as the specified StringBuffer.
Methods of String(Cont…)
Working with methods using Strings
 Like other values to (parameters)methods, Strings
also can be passed to methods.
Ex:
public String printString(String s) {
System.out.println(s);
return “modified”+s;
}
String newString =printString(new
String(“Java”));//invoking an array
Necessity of StringBuffer
 String objects are immutable,meaning
modifications to the string object cannot be done
once created. If done a new String Object will be
created in memory.
 The StringBuffer and StringBuilder classes are
used when there is a necessity to make alot of
modifications to Strings of characters.
 StringBuffer and Stringbuilder can be modified
over and over again with out leaving behind alot
of new unused objects.
String Buffers Methods
 public StringBuffer append(String s)
Updates the value of the object that invoked the
method. The method takes boolean, char, int,
long, Strings etc.
 public StringBuffer reverse()
The method reverses the value of the
StringBuffer object that invoked the method.
 public delete(int start, int end)
Deletes the string starting from start index until
end index.
String Buffers Methods
 void setLength(int newLength)
Sets the length of this String buffer.
 int length()
Returns the length (character count) of this string
buffer.
 void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least
equal to the specified minimum.
 int capacity()
Returns the current capacity of the String buffer.
String Builder Methods
 int length()
Returns the length (character count) of this string
buffer.
 void ensureCapacity(int minimumCapacity)
Ensures that the capacity of the buffer is at least
equal to the specified minimum.
 int capacity()
Returns the current capacity of the String buffer.
 reverse() :Causes this character sequence to be
replaced by the reverse of the sequence.
StringBuilder vs StringBuffer
 Below is a table that contains differences between
StringBuilder and StringBuffer.
StringBuffer StringBuilder
It is mutable It is mutable
It is
synchronized,provides
ThreadSafety.
It is non
synchronized.Provides no
ThreadSafety.
Capacity increases
automatically .
Capacity increases
automatically .
Excercise
 Create an application that will convert a given
character array to a string.
 Creat an application that will create a reverse of
a string.
 Create an application that uses StringBuffer to
concatinate the user input.
 Create an application that uses a StringBuilder
and String Buffer and insert one in another.
 Thank You

More Related Content

Similar to Java Strings methods and operations.ppt (20)

Strings in Java
Strings in JavaStrings in Java
Strings in Java
Abhilash Nair
 
Java String
Java String Java String
Java String
SATYAM SHRIVASTAV
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
SanthiyaAK
 
String.ppt
String.pptString.ppt
String.ppt
ajeela mushtaq
 
Java Strings
Java StringsJava Strings
Java Strings
RaBiya Chaudhry
 
Day_5.1.pptx
Day_5.1.pptxDay_5.1.pptx
Day_5.1.pptx
ishasharma835109
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
teach4uin
 
Java String Handling
Java String HandlingJava String Handling
Java String Handling
Infoviaan Technologies
 
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
 
Java String class
Java String classJava String class
Java String class
DrRajeshreeKhande
 
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
 
Java string handling
Java string handlingJava string handling
Java string handling
GaneshKumarKanthiah
 
Text processing
Text processingText processing
Text processing
Icancode
 
Java string , string buffer and wrapper class
Java string , string buffer and wrapper classJava string , string buffer and wrapper class
Java string , string buffer and wrapper class
SimoniShah6
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 
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
 
M C6java7
M C6java7M C6java7
M C6java7
mbruggen
 
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
OUM SAOKOSAL
 
Strings
StringsStrings
Strings
naslin prestilda
 
Charcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.pptCharcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.ppt
mulualem37
 
L13 string handling(string class)
L13 string handling(string class)L13 string handling(string class)
L13 string handling(string class)
teach4uin
 
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
 
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
 
Text processing
Text processingText processing
Text processing
Icancode
 
Java string , string buffer and wrapper class
Java string , string buffer and wrapper classJava string , string buffer and wrapper class
Java string , string buffer and wrapper class
SimoniShah6
 
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
 
Charcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.pptCharcater and Strings.ppt Charcater and Strings.ppt
Charcater and Strings.ppt Charcater and Strings.ppt
mulualem37
 

More from JyothiAmpally (19)

node.js interview questions and answers.
node.js interview questions and answers.node.js interview questions and answers.
node.js interview questions and answers.
JyothiAmpally
 
Exception and ErrorHandling in Java .ppt
Exception and ErrorHandling in Java .pptException and ErrorHandling in Java .ppt
Exception and ErrorHandling in Java .ppt
JyothiAmpally
 
Arrays Basicfundamentaldatastructure.ppt
Arrays Basicfundamentaldatastructure.pptArrays Basicfundamentaldatastructure.ppt
Arrays Basicfundamentaldatastructure.ppt
JyothiAmpally
 
_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt
JyothiAmpally
 
Java-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.pptJava-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
Java Operators explained _in __brief.ppt
Java Operators explained _in __brief.pptJava Operators explained _in __brief.ppt
Java Operators explained _in __brief.ppt
JyothiAmpally
 
UML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .pptUML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .ppt
JyothiAmpally
 
OOPS_AbstractClasses_explained__java.ppt
OOPS_AbstractClasses_explained__java.pptOOPS_AbstractClasses_explained__java.ppt
OOPS_AbstractClasses_explained__java.ppt
JyothiAmpally
 
Java_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.pptJava_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.ppt
JyothiAmpally
 
Java_gui_with_AWT_and_its_components.ppt
Java_gui_with_AWT_and_its_components.pptJava_gui_with_AWT_and_its_components.ppt
Java_gui_with_AWT_and_its_components.ppt
JyothiAmpally
 
1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt
JyothiAmpally
 
01-basics-functions.ppt
01-basics-functions.ppt01-basics-functions.ppt
01-basics-functions.ppt
JyothiAmpally
 
03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
25-functions.ppt
25-functions.ppt25-functions.ppt
25-functions.ppt
JyothiAmpally
 
03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
02-Java Technology Details.ppt
02-Java Technology Details.ppt02-Java Technology Details.ppt
02-Java Technology Details.ppt
JyothiAmpally
 
01-Java Introduction.ppt
01-Java Introduction.ppt01-Java Introduction.ppt
01-Java Introduction.ppt
JyothiAmpally
 
01_What is Java.ppt
01_What is Java.ppt01_What is Java.ppt
01_What is Java.ppt
JyothiAmpally
 
Spring security
Spring securitySpring security
Spring security
JyothiAmpally
 
node.js interview questions and answers.
node.js interview questions and answers.node.js interview questions and answers.
node.js interview questions and answers.
JyothiAmpally
 
Exception and ErrorHandling in Java .ppt
Exception and ErrorHandling in Java .pptException and ErrorHandling in Java .ppt
Exception and ErrorHandling in Java .ppt
JyothiAmpally
 
Arrays Basicfundamentaldatastructure.ppt
Arrays Basicfundamentaldatastructure.pptArrays Basicfundamentaldatastructure.ppt
Arrays Basicfundamentaldatastructure.ppt
JyothiAmpally
 
_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt_Java__Expressions__and__FlowControl.ppt
_Java__Expressions__and__FlowControl.ppt
JyothiAmpally
 
Java-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.pptJava-Variables_about_different_Scope.ppt
Java-Variables_about_different_Scope.ppt
JyothiAmpally
 
Java Operators explained _in __brief.ppt
Java Operators explained _in __brief.pptJava Operators explained _in __brief.ppt
Java Operators explained _in __brief.ppt
JyothiAmpally
 
UML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .pptUML to Object Oriented Mapping java .ppt
UML to Object Oriented Mapping java .ppt
JyothiAmpally
 
OOPS_AbstractClasses_explained__java.ppt
OOPS_AbstractClasses_explained__java.pptOOPS_AbstractClasses_explained__java.ppt
OOPS_AbstractClasses_explained__java.ppt
JyothiAmpally
 
Java_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.pptJava_Identifiers_keywords_data_types.ppt
Java_Identifiers_keywords_data_types.ppt
JyothiAmpally
 
Java_gui_with_AWT_and_its_components.ppt
Java_gui_with_AWT_and_its_components.pptJava_gui_with_AWT_and_its_components.ppt
Java_gui_with_AWT_and_its_components.ppt
JyothiAmpally
 
1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt1. Introduction to HTML5.ppt
1. Introduction to HTML5.ppt
JyothiAmpally
 
01-basics-functions.ppt
01-basics-functions.ppt01-basics-functions.ppt
01-basics-functions.ppt
JyothiAmpally
 
03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt03_A-OOPs_Interfaces.ppt
03_A-OOPs_Interfaces.ppt
JyothiAmpally
 
02-Java Technology Details.ppt
02-Java Technology Details.ppt02-Java Technology Details.ppt
02-Java Technology Details.ppt
JyothiAmpally
 
01-Java Introduction.ppt
01-Java Introduction.ppt01-Java Introduction.ppt
01-Java Introduction.ppt
JyothiAmpally
 
Ad

Recently uploaded (20)

Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
Pfeiffer "Secrets to Changing Behavior in Scholarly Communication: A 2025 NIS...
National Information Standards Organization (NISO)
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
BUSINESS QUIZ PRELIMS | QUIZ CLUB OF PSGCAS | 9 SEPTEMBER 2024
Quiz Club of PSG College of Arts & Science
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
TV Shows and web-series quiz | QUIZ CLUB OF PSGCAS | 13TH MARCH 2025
Quiz Club of PSG College of Arts & Science
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptxRai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Rai dyansty Chach or Brahamn dynasty, History of Dahir History of Sindh NEP.pptx
Dr. Ravi Shankar Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
Nice Dream.pdf /
Nice Dream.pdf                              /Nice Dream.pdf                              /
Nice Dream.pdf /
ErinUsher3
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 EmployeeHow to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
Respiratory System , Urinary System
Respiratory  System , Urinary SystemRespiratory  System , Urinary System
Respiratory System , Urinary System
RushiMandali
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdfUnit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_HyderabadWebcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Webcrawler_Mule_AIChain_MuleSoft_Meetup_Hyderabad
Veera Pallapu
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdfAllomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18How to Manage Maintenance Request in Odoo 18
How to Manage Maintenance Request in Odoo 18
Celine George
 
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
Trends Spotting Strategic foresight for tomorrow’s education systems - Debora...
EduSkills OECD
 
How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18How to Configure Vendor Management in Lunch App of Odoo 18
How to Configure Vendor Management in Lunch App of Odoo 18
Celine George
 
Ray Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big CycleRay Dalio How Countries go Broke the Big Cycle
Ray Dalio How Countries go Broke the Big Cycle
Dadang Solihin
 
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17Different pricelists for different shops in odoo Point of Sale in Odoo 17
Different pricelists for different shops in odoo Point of Sale in Odoo 17
Celine George
 
Final Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptxFinal Sketch Designs for poster production.pptx
Final Sketch Designs for poster production.pptx
bobby205207
 
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptxAnalysis of Quantitative Data Parametric and non-parametric tests.pptx
Analysis of Quantitative Data Parametric and non-parametric tests.pptx
Shrutidhara2
 
Parenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independenceParenting Teens: Supporting Trust, resilience and independence
Parenting Teens: Supporting Trust, resilience and independence
Pooky Knightsmith
 
Adam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational PsychologyAdam Grant: Transforming Work Culture Through Organizational Psychology
Adam Grant: Transforming Work Culture Through Organizational Psychology
Prachi Shah
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti MpdBasic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Ad

Java Strings methods and operations.ppt

  • 2. ● This module introduces the participants to the string object. ● Importance of String Objects and How to create them. ● Varioius Constructors that are available to create Strings. ● Working with methods that are available with strings. ● Understanding Necessity of StringBuffer class. ● Working with methods of StringBuffer class. ● Introduction to StringBuilder class. ● Working with methods of StringBuilder class. Module Overview 2
  • 3.  Uderstand the concept of Strings and create string objects.  Understand advantages and disadvantages of Strings.  Declare and create Strings using different types of constructors.  Working with Strings and its different types of methods.  Determine the usage of String Buffer and StringBuilder. Objectives 3
  • 4. String: Strings are a sequence of characters, which are implemented as objects. Charecteristics of Strings: • The String class is immutable,meaning once created a String object cannot be changed. • If any modifications is done to the existing string object a new object is created internally. • String objects are created by using the new keyword and a constructor. The String class has eleven constructors that allow you to provide the initial value of the string using different sources, such as an array of characters. String 4
  • 5. String Declaration String Declaration: The most direct way to create a string is as follows; String greeting = "Hello world!";//String literal Other Common Declarations: String helloString = new String(helloArray); char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'};
  • 6. Example of String Class. public class StringDemo{ public static void main(String args[]){ char[] helloArray = { 'h', 'e', 'l', 'l', 'o', '.'}; String helloString = new String(helloArray); String helloString2 = new String(“hello!!!”); System.out.println( helloString ); } } Output:hello.
  • 7. Methods Of String  Accessor:Methods used to obtain information about an object are known as accessor methods. One accessor method that you can use with strings is the length() method, which returns the number of characters contained in the string object. Syntax: <StringOBject>.length(); Example: String name = “java”; int length = name.length();
  • 8. Methods of String(Cont…) Concatenating Strings:One String can be concatenated to another string.This will produce a new string object joining two strings. Strings are more commonly concatenated with the + operator and concat method. Syntax: string1.concat(string2); string1+string2
  • 9. Methods of String(Cont…)  String substring(int beginIndex) Returns a new string that is a substring of this string.  char[] toCharArray() Converts this string to a new character array.  String toLowerCase() Converts all of the characters in this String to lower case using the rules of the default locale.  String replace(char oldChar, char newChar) Returns a new string resulting from replacing all occurrences of oldChar in this string with newChar.  String[] split(String regex) Splits this string around matches of the given regular expression.
  • 10.  String toString() This object (which is already a string!) is itself returned.  String toUpperCase() Converts all of the characters in this String to upper case using the rules of the default locale.  String trim() Returns a copy of the string, with leading and trailing whitespace omitted.  boolean startsWith(String prefix) Tests if this string starts with the specified prefix.  boolean contentEquals(StringBuffer sb) Returns true if and only if this String represents the same sequence of characters as the specified StringBuffer. Methods of String(Cont…)
  • 11. Working with methods using Strings  Like other values to (parameters)methods, Strings also can be passed to methods. Ex: public String printString(String s) { System.out.println(s); return “modified”+s; } String newString =printString(new String(“Java”));//invoking an array
  • 12. Necessity of StringBuffer  String objects are immutable,meaning modifications to the string object cannot be done once created. If done a new String Object will be created in memory.  The StringBuffer and StringBuilder classes are used when there is a necessity to make alot of modifications to Strings of characters.  StringBuffer and Stringbuilder can be modified over and over again with out leaving behind alot of new unused objects.
  • 13. String Buffers Methods  public StringBuffer append(String s) Updates the value of the object that invoked the method. The method takes boolean, char, int, long, Strings etc.  public StringBuffer reverse() The method reverses the value of the StringBuffer object that invoked the method.  public delete(int start, int end) Deletes the string starting from start index until end index.
  • 14. String Buffers Methods  void setLength(int newLength) Sets the length of this String buffer.  int length() Returns the length (character count) of this string buffer.  void ensureCapacity(int minimumCapacity) Ensures that the capacity of the buffer is at least equal to the specified minimum.  int capacity() Returns the current capacity of the String buffer.
  • 15. String Builder Methods  int length() Returns the length (character count) of this string buffer.  void ensureCapacity(int minimumCapacity) Ensures that the capacity of the buffer is at least equal to the specified minimum.  int capacity() Returns the current capacity of the String buffer.  reverse() :Causes this character sequence to be replaced by the reverse of the sequence.
  • 16. StringBuilder vs StringBuffer  Below is a table that contains differences between StringBuilder and StringBuffer. StringBuffer StringBuilder It is mutable It is mutable It is synchronized,provides ThreadSafety. It is non synchronized.Provides no ThreadSafety. Capacity increases automatically . Capacity increases automatically .
  • 17. Excercise  Create an application that will convert a given character array to a string.  Creat an application that will create a reverse of a string.  Create an application that uses StringBuffer to concatinate the user input.  Create an application that uses a StringBuilder and String Buffer and insert one in another.

Editor's Notes

  • #2: Instructor Notes:
  • #3: Instructor Notes: By the end of this module, participants should be able to: <Obj1> <Obj 2>
  • #4: Instructor Notes: