ºÝºÝߣ

ºÝºÝߣShare a Scribd company logo
STRINGS
Strings represents a sequence of charcters
Ex:
char Name[]= new char[5];
Name[0]=¡®r¡¯
Name[1]=¡®a¡¯
Name[2]=¡®j¡¯
Name[3]=¡®a¡¯
Name[4]=¡®h¡¯
In java strings are class objects implemented by two classes
1. String class and
2. StringBuffer class
String class is used to create strings of fixed length
And StringBuffer class creates strings of flexible length
which can be modified in terms of length and content
STRINGS
A java string is an instantiated object of String class
A java string is not a character array and it is not
Null terminated.
A string can be created as follows
String stringname;
stringname = new String(¡°string¡±);
Ex: String collegename;
collegename = new String(¡°Rajah college¡±);
STRINGS
Like arrays we can find the length of a string by
using length() method.
Ex:
int length= collegename.length();
length=13
Java strings can be concatenated using ¡°+ ¡° operator
ex:
String strin1=¡°rajah¡±
String string2=¡°college¡±
String string3= string1+string2;
string=¡°rajahcollege¡±
SRINGS
String arrays:
We can also creat arrays that contain strings.
String names[]=new String[3];
String methods:
s2=s1.toLowerCase
Converts the string s1 to all lower case
s2=s1.toUpperCase
Convers the string s1 to all Upper case
STRINGS
s2=s1.replace(¡®x¡¯ , ¡®y¡¯)
Replaces all the appearance of ¡®x¡¯ with ¡®y¡¯
s2=s1.trim()
Removes the white spaces at the beginning and end
of the string s1.
s1.equals(s2)
Returns true if s1 is equal to s2
s1.equalsIgnoreCase(s2)
Returns true if s1 is equal to s2 by ignoring case
s1.length()
Returns the length of the string s1
STRINGS
s1.charAt(n)
It returns the character at positon
s1.compareTo(s2)
Returns true if s1<s2, positive if s1>s2 and zero if
s1=s2
s1.concate(s2)
Concatenates s1 and s2
STRINGS
s1.subString(n)
Give s a substring starting from nth character
s1.subString(n,m)
Gives a substring starting from nth character upto mth
not including mth character.
s1.indexOf(¡®x¡¯)
Gives the postion of first appearance of x in string s1
s1.indexOf(¡®x¡¯,n)
Gives the first appearance of ¡®x¡¯ after nth position in
string s1
STRINGBUFFER CLASS
StringBuffer class is used to create strings of flexible
length.
Strings that are created by using StringBuffer class
can be modified both in terms of length and content.
Ex:
StringBuffer str= new StringBuffer(¡°object
language¡±)
StringBuffer class methods:
s1.setCharAt(n,¡¯x¡¯)
Modifies the nth character to x.
s1.append(s2)
Appends the string s2 to the end of s1
STRINGBUFFER CLASS
s1.insert(n,s2)
Inserts the string s2 at the postion n of the string
s1
s1.setLength(n)
Set the length of the string s1 to n. If n<s1.length()
S1 is truncated. If n>s1.length(). Zeros are added.

More Related Content

Similar to STRING FUNCTIONS IN JAVA BY N SARATH KUMAR (20)

Strings Arrays
Strings ArraysStrings Arrays
Strings Arrays
phanleson
?
Chapter 7 String
Chapter 7 StringChapter 7 String
Chapter 7 String
OUM SAOKOSAL
?
Java
JavaJava
Java
JahnaviBhagat
?
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
?
String in programming language in c or c++
String in programming language in c or c++String in programming language in c or c++
String in programming language in c or c++
Azeemaj101
?
Python programming : Strings
Python programming : StringsPython programming : Strings
Python programming : Strings
Emertxe Information Technologies Pvt Ltd
?
String notes
String notesString notes
String notes
Prasadu Peddi
?
String Methods and Files
String Methods and FilesString Methods and Files
String Methods and Files
Pooja B S
?
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
?
Strings
StringsStrings
Strings
naslin prestilda
?
javastringexample problems using string class
javastringexample problems using string classjavastringexample problems using string class
javastringexample problems using string class
fedcoordinator
?
Team 1
Team 1Team 1
Team 1
Sathasivam Rangasamy
?
Java Strings
Java StringsJava Strings
Java Strings
RaBiya Chaudhry
?
Strings in java
Strings in javaStrings in java
Strings in java
Kuppusamy P
?
StringBuffer.pptx
StringBuffer.pptxStringBuffer.pptx
StringBuffer.pptx
meenakshi pareek
?
M C6java7
M C6java7M C6java7
M C6java7
mbruggen
?
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
mohithn2004
?
Java string handling
Java string handlingJava string handling
Java string handling
Salman Khan
?
Python strings
Python stringsPython strings
Python strings
Mohammed Sikander
?
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
?

Recently uploaded (20)

The metaverse : A Digital Transformation
The metaverse : A Digital TransformationThe metaverse : A Digital Transformation
The metaverse : A Digital Transformation
matlotloatang03
?
Network_Packet_Brokers_Presentation.pptx
Network_Packet_Brokers_Presentation.pptxNetwork_Packet_Brokers_Presentation.pptx
Network_Packet_Brokers_Presentation.pptx
Khushi Communications
?
Innovative Web Design | Malachite Technologies
Innovative Web Design | Malachite TechnologiesInnovative Web Design | Malachite Technologies
Innovative Web Design | Malachite Technologies
malachitetechnologie1
?
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD TechnicianRicardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno
?
Build Your Uber Clone App with Advanced Features
Build Your Uber Clone App with Advanced FeaturesBuild Your Uber Clone App with Advanced Features
Build Your Uber Clone App with Advanced Features
V3cube
?
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdfCybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Joe Shenouda
?
Automated Engineering of Domain-Specific Metamorphic Testing Environments
Automated Engineering of Domain-Specific Metamorphic Testing EnvironmentsAutomated Engineering of Domain-Specific Metamorphic Testing Environments
Automated Engineering of Domain-Specific Metamorphic Testing Environments
Pablo G¨®mez Abajo
?
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable WorkflowsMastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Callon Campbell
?
Benefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle CloudBenefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle Cloud
AstuteBusiness
?
Next.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web AppsNext.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web Apps
rwinfotech31
?
APAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdfAPAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdf
GDG on Campus Monash
?
San Francisco Atlassian ACE - Mar 27 2025.pdf
San Francisco Atlassian ACE - Mar 27 2025.pdfSan Francisco Atlassian ACE - Mar 27 2025.pdf
San Francisco Atlassian ACE - Mar 27 2025.pdf
Matt Doar
?
Why Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdfWhy Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdf
anjelinajones6811
?
Columbia Weather Systems - Product Overview
Columbia Weather Systems - Product OverviewColumbia Weather Systems - Product Overview
Columbia Weather Systems - Product Overview
Columbia Weather Systems
?
Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]
Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]
Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]
jackalen173
?
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-WorldAll-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
Safe Software
?
The Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptxThe Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptx
zsbaranyai
?
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
202408_JAWSPANKRATION_Introduction_of_Minaden.pdf
NTTDOCOMO-ServiceInnovation
?
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and FeastSmarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Zilliz
?
Automating Behavior-Driven Development: Boosting Productivity with Template-D...
Automating Behavior-Driven Development: Boosting Productivity with Template-D...Automating Behavior-Driven Development: Boosting Productivity with Template-D...
Automating Behavior-Driven Development: Boosting Productivity with Template-D...
DOCOMO Innovations, Inc.
?
The metaverse : A Digital Transformation
The metaverse : A Digital TransformationThe metaverse : A Digital Transformation
The metaverse : A Digital Transformation
matlotloatang03
?
Innovative Web Design | Malachite Technologies
Innovative Web Design | Malachite TechnologiesInnovative Web Design | Malachite Technologies
Innovative Web Design | Malachite Technologies
malachitetechnologie1
?
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD TechnicianRicardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno - A Structural CAD Technician
Ricardo Jebb Bruno
?
Build Your Uber Clone App with Advanced Features
Build Your Uber Clone App with Advanced FeaturesBuild Your Uber Clone App with Advanced Features
Build Your Uber Clone App with Advanced Features
V3cube
?
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdfCybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Cybersecurity-Threat-Landscape-March-31-April-7-2025.pdf
Joe Shenouda
?
Automated Engineering of Domain-Specific Metamorphic Testing Environments
Automated Engineering of Domain-Specific Metamorphic Testing EnvironmentsAutomated Engineering of Domain-Specific Metamorphic Testing Environments
Automated Engineering of Domain-Specific Metamorphic Testing Environments
Pablo G¨®mez Abajo
?
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable WorkflowsMastering Azure Durable Functions - Building Resilient and Scalable Workflows
Mastering Azure Durable Functions - Building Resilient and Scalable Workflows
Callon Campbell
?
Benefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle CloudBenefits of Moving Ellucian Banner to Oracle Cloud
Benefits of Moving Ellucian Banner to Oracle Cloud
AstuteBusiness
?
Next.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web AppsNext.js Development: The Ultimate Solution for High-Performance Web Apps
Next.js Development: The Ultimate Solution for High-Performance Web Apps
rwinfotech31
?
APAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdfAPAC Solutions Challenge Info Session.pdf
APAC Solutions Challenge Info Session.pdf
GDG on Campus Monash
?
San Francisco Atlassian ACE - Mar 27 2025.pdf
San Francisco Atlassian ACE - Mar 27 2025.pdfSan Francisco Atlassian ACE - Mar 27 2025.pdf
San Francisco Atlassian ACE - Mar 27 2025.pdf
Matt Doar
?
Why Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdfWhy Outsource Accounting to India A Smart Business Move!.pdf
Why Outsource Accounting to India A Smart Business Move!.pdf
anjelinajones6811
?
Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]
Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]
Fast Screen Recorder v2.1.0.11 Crack Updated [April-2025]
jackalen173
?
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-WorldAll-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
All-Data, Any-AI Integration: FME & Amazon Bedrock in the Real-World
Safe Software
?
The Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptxThe Road to SAP S4HANA Cloud with SAP Activate.pptx
The Road to SAP S4HANA Cloud with SAP Activate.pptx
zsbaranyai
?
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and FeastSmarter RAG Pipelines: Scaling Search with Milvus and Feast
Smarter RAG Pipelines: Scaling Search with Milvus and Feast
Zilliz
?
Automating Behavior-Driven Development: Boosting Productivity with Template-D...
Automating Behavior-Driven Development: Boosting Productivity with Template-D...Automating Behavior-Driven Development: Boosting Productivity with Template-D...
Automating Behavior-Driven Development: Boosting Productivity with Template-D...
DOCOMO Innovations, Inc.
?

STRING FUNCTIONS IN JAVA BY N SARATH KUMAR

  • 1. STRINGS Strings represents a sequence of charcters Ex: char Name[]= new char[5]; Name[0]=¡®r¡¯ Name[1]=¡®a¡¯ Name[2]=¡®j¡¯ Name[3]=¡®a¡¯ Name[4]=¡®h¡¯ In java strings are class objects implemented by two classes 1. String class and 2. StringBuffer class String class is used to create strings of fixed length And StringBuffer class creates strings of flexible length which can be modified in terms of length and content
  • 2. STRINGS A java string is an instantiated object of String class A java string is not a character array and it is not Null terminated. A string can be created as follows String stringname; stringname = new String(¡°string¡±); Ex: String collegename; collegename = new String(¡°Rajah college¡±);
  • 3. STRINGS Like arrays we can find the length of a string by using length() method. Ex: int length= collegename.length(); length=13 Java strings can be concatenated using ¡°+ ¡° operator ex: String strin1=¡°rajah¡± String string2=¡°college¡± String string3= string1+string2; string=¡°rajahcollege¡±
  • 4. SRINGS String arrays: We can also creat arrays that contain strings. String names[]=new String[3]; String methods: s2=s1.toLowerCase Converts the string s1 to all lower case s2=s1.toUpperCase Convers the string s1 to all Upper case
  • 5. STRINGS s2=s1.replace(¡®x¡¯ , ¡®y¡¯) Replaces all the appearance of ¡®x¡¯ with ¡®y¡¯ s2=s1.trim() Removes the white spaces at the beginning and end of the string s1. s1.equals(s2) Returns true if s1 is equal to s2 s1.equalsIgnoreCase(s2) Returns true if s1 is equal to s2 by ignoring case s1.length() Returns the length of the string s1
  • 6. STRINGS s1.charAt(n) It returns the character at positon s1.compareTo(s2) Returns true if s1<s2, positive if s1>s2 and zero if s1=s2 s1.concate(s2) Concatenates s1 and s2
  • 7. STRINGS s1.subString(n) Give s a substring starting from nth character s1.subString(n,m) Gives a substring starting from nth character upto mth not including mth character. s1.indexOf(¡®x¡¯) Gives the postion of first appearance of x in string s1 s1.indexOf(¡®x¡¯,n) Gives the first appearance of ¡®x¡¯ after nth position in string s1
  • 8. STRINGBUFFER CLASS StringBuffer class is used to create strings of flexible length. Strings that are created by using StringBuffer class can be modified both in terms of length and content. Ex: StringBuffer str= new StringBuffer(¡°object language¡±) StringBuffer class methods: s1.setCharAt(n,¡¯x¡¯) Modifies the nth character to x. s1.append(s2) Appends the string s2 to the end of s1
  • 9. STRINGBUFFER CLASS s1.insert(n,s2) Inserts the string s2 at the postion n of the string s1 s1.setLength(n) Set the length of the string s1 to n. If n<s1.length() S1 is truncated. If n>s1.length(). Zeros are added.