SlideShare a Scribd company logo
java.lang.String class
In Java a String is an object of class java.lang.String and we can make the string objects by calling String
constructors. The constructors of java.lang.String classes are overloaded some of them are

Creating an empty String
String s = new String();
Creating a string with character array
String fromCharArray = new String(char[] arr);
Creating a string from character array with specified index and number of characters
String fromCharArray = new String(char[], int startIndex, int numberOfCharacters);
Creating a string from another string
String copy = new String(String s);
Methods of java.lang.String class



length()
The method length is used to find the length of a String object.
Declaration
public int length();
Usage
String s = “Alex Vipul Verma”;
int len = s.length();
toString()
The method toString() is an instance method of Object class and overridden by most of the classes
in Java API. It is used to convert any reference data type into String for readable from
Declaration
public String toString();
Usage
Object ob = new Object();
String s = ob.toString();
getBytes()
The method getBytes() is used to create a byte array from the String with the ASCII values of
individual characters
Declaration
public byte[] getBytes();
Usage
String s = “ABCD”;
byte[] arr = new byte[s.length()];
arr = s.getBytes();
Here the array arr is generated as
byte arr = {65, 66, 67, 68};
toCharArray()
The method toCharArray() is similar to getBytes(). The method getBytes() generates the byte type
array and char Array generates char type array
Declaration
public char[] toCharArray();
Usage
String s = “Hello!”;
char[] arr = new char[s.length];
arr = s.toCharArray();
Here the character array arr is generated as
char arr = {‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘!’};
equals() and equalsIgnoreCase()
The method equals() is used to check the equality of two given strings. It returns true if the
strings are equal. equalsIgnoreCase() is similar to equals() but it ignore the cases of strings
Declaration
public boolean equals(String s);
public boolean equalsIgnoreCase(String s);
Usage
boolean result1 = “Alex”.equals(“Alex”);
boolean result2 = “Hello”.equals(“HELLO”);
startsWith() and endsWith()
These two methods are overloaded. They are used to check whether a String is starting (or ending)
with specified character or NOT
Declaration
public boolean startsWith(char ch);
public boolean startsWith(String s);
public boolean endsWith(char ch);
public boolean startsWith(String s);


charAt(index)
The method charAt() is used to find the character at the specified index from a String
Declaration
public char charAt(int index);
Usage
String s = “Alex Vipul Verma”;
char ch = s.charAt(10);
indexOf() and lastIndexOf()
These two methods are also overloaded to take string and character type parameter. They are used
to get the index of specified character or string into the existing string. They return -1 if the
argument did NOT found into the calling String.
Declaration
public int indexOf(char ch);
public int indexOf(String s);
public int lastIndexOf(char ch);
public int lastIndexOf(String s);
substring()
substring() is an overloaded method. Used to create a substring from another string. It is helpful
to obtain a copy of string with the specified number of characters and starting index
Declaration
public String substring(int startIndex);
public String substring(int startIndex, endIndex);
trim()
The method trim() is used to remove the unnecessary whitespaces from a given string.
Declaration
public String trim();
toUpperCase() and toLowerCase()
These two methods are used to convert all the characters of a string to uppercase or lowercase.
The String objects are immutable so they do NOT modify the existing String but they return a copy
of modified String.
Declaration
public String toUpperCase();
public String toLowerCase();
java.lang.String Class

More Related Content

What's hot

String Handling
String HandlingString Handling
String Handling
Bharat17485
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
Hyderabad Scalability Meetup
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
Knoldus Inc.
 
Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享
LearningTech
 
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
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
Mohammed Sikander
 
Methods common to all objects
Methods common to all objectsMethods common to all objects
Methods common to all objects
Sandeep Chawla
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
SSN College of Engineering, Kalavakkam
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
Praveen M Jigajinni
 
Dictionaries
DictionariesDictionaries
Dictionaries
mansoura University
 
String handling session 5
String handling session 5String handling session 5
String handling session 5
Raja Sekhar
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
Manav Prasad
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
Neelkanth Sachdeva
 
Lecture 7
Lecture 7Lecture 7
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
Knoldus Inc.
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
Prem Kumar Badri
 
String in python lecture (3)
String in python lecture (3)String in python lecture (3)
String in python lecture (3)
Ali ٍSattar
 
Ruby data types and objects
Ruby   data types and objectsRuby   data types and objects
Ruby data types and objects
Harkamal Singh
 
Arrays
ArraysArrays
Arrays
Faisal Aziz
 
Python strings
Python stringsPython strings
Python strings
Mohammed Sikander
 

What's hot (20)

String Handling
String HandlingString Handling
String Handling
 
Java 8 Lambda Expressions
Java 8 Lambda ExpressionsJava 8 Lambda Expressions
Java 8 Lambda Expressions
 
Pattern Matching - at a glance
Pattern Matching - at a glancePattern Matching - at a glance
Pattern Matching - at a glance
 
Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享Covariance, contravariance 觀念分享
Covariance, contravariance 觀念分享
 
L14 string handling(string buffer class)
L14 string handling(string buffer class)L14 string handling(string buffer class)
L14 string handling(string buffer class)
 
Python dictionary
Python   dictionaryPython   dictionary
Python dictionary
 
Methods common to all objects
Methods common to all objectsMethods common to all objects
Methods common to all objects
 
String, string builder, string buffer
String, string builder, string bufferString, string builder, string buffer
String, string builder, string buffer
 
Chapter 14 strings
Chapter 14 stringsChapter 14 strings
Chapter 14 strings
 
Dictionaries
DictionariesDictionaries
Dictionaries
 
String handling session 5
String handling session 5String handling session 5
String handling session 5
 
Java 8 streams
Java 8 streamsJava 8 streams
Java 8 streams
 
Functional programming with Scala
Functional programming with ScalaFunctional programming with Scala
Functional programming with Scala
 
Lecture 7
Lecture 7Lecture 7
Lecture 7
 
Functions & closures
Functions & closuresFunctions & closures
Functions & closures
 
Module 7 : Arrays
Module 7 : ArraysModule 7 : Arrays
Module 7 : Arrays
 
String in python lecture (3)
String in python lecture (3)String in python lecture (3)
String in python lecture (3)
 
Ruby data types and objects
Ruby   data types and objectsRuby   data types and objects
Ruby data types and objects
 
Arrays
ArraysArrays
Arrays
 
Python strings
Python stringsPython strings
Python strings
 

Similar to java.lang.String Class

String and string buffer
String and string bufferString and string buffer
String and string buffer
kamal kotecha
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
Eduardo Bergavera
 
M C6java7
M C6java7M C6java7
M C6java7
mbruggen
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
Vince Vo
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
SanthiyaAK
 
07slide
07slide07slide
07slide
Aboudi Sabbah
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
MLG College of Learning, Inc
 
package
packagepackage
package
sweetysweety8
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
learnEnglish51
 
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 handling
String handlingString handling
String handling
ssuser20c32b
 
String notes
String notesString notes
String notes
Prasadu Peddi
 
Strings
StringsStrings
Strings
Imad Ali
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
Indu32
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
SowmyaJyothi3
 
13 Strings and text processing
13 Strings and text processing13 Strings and text processing
13 Strings and text processing
maznabili
 
Strings in java
Strings in javaStrings in java
Strings in java
Kuppusamy P
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
adityaraj7711
 
Strings in c
Strings in cStrings in c
Strings in c
vampugani
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
Sardar Alam
 

Similar to java.lang.String Class (20)

String and string buffer
String and string bufferString and string buffer
String and string buffer
 
Chapter 9 - Characters and Strings
Chapter 9 - Characters and StringsChapter 9 - Characters and Strings
Chapter 9 - Characters and Strings
 
M C6java7
M C6java7M C6java7
M C6java7
 
Java căn bản - Chapter9
Java căn bản - Chapter9Java căn bản - Chapter9
Java căn bản - Chapter9
 
Strings.ppt
Strings.pptStrings.ppt
Strings.ppt
 
07slide
07slide07slide
07slide
 
Computer programming 2 Lesson 12
Computer programming 2  Lesson 12Computer programming 2  Lesson 12
Computer programming 2 Lesson 12
 
package
packagepackage
package
 
Module-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdfModule-1 Strings Handling.ppt.pdf
Module-1 Strings Handling.ppt.pdf
 
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
 
String handling
String handlingString handling
String handling
 
String notes
String notesString notes
String notes
 
Strings
StringsStrings
Strings
 
In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...In the given example only one object will be created. Firstly JVM will not fi...
In the given example only one object will be created. Firstly JVM will not fi...
 
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdfSTRINGS IN C MRS.SOWMYA JYOTHI.pdf
STRINGS IN C MRS.SOWMYA JYOTHI.pdf
 
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
 
Programing with java for begniers .pptx
Programing with java for begniers  .pptxPrograming with java for begniers  .pptx
Programing with java for begniers .pptx
 
Strings in c
Strings in cStrings in c
Strings in c
 
Arrays string handling java packages
Arrays string handling java packagesArrays string handling java packages
Arrays string handling java packages
 

Recently uploaded

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
panagenda
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
Edge AI and Vision Alliance
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
DanBrown980551
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
Matthew Sinclair
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
saastr
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
ssuserfac0301
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
David Brossard
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
Daiki Mogmet Ito
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
Hiroshi SHIBATA
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
Tatiana Kojar
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
Octavian Nadolu
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
Zilliz
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
jpupo2018
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
Quotidiano Piemontese
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Alpen-Adria-Universität
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
Wouter Lemaire
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Malak Abu Hammad
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Tosin Akinosho
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
Postman
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
Brandon Minnick, MBA
 

Recently uploaded (20)

HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAUHCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
HCL Notes und Domino Lizenzkostenreduzierung in der Welt von DLAU
 
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
“Building and Scaling AI Applications with the Nx AI Manager,” a Presentation...
 
5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides5th LF Energy Power Grid Model Meet-up Slides
5th LF Energy Power Grid Model Meet-up Slides
 
20240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 202420240607 QFM018 Elixir Reading List May 2024
20240607 QFM018 Elixir Reading List May 2024
 
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
Deep Dive: AI-Powered Marketing to Get More Leads and Customers with HyperGro...
 
Taking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdfTaking AI to the Next Level in Manufacturing.pdf
Taking AI to the Next Level in Manufacturing.pdf
 
OpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - AuthorizationOpenID AuthZEN Interop Read Out - Authorization
OpenID AuthZEN Interop Read Out - Authorization
 
How to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For FlutterHow to use Firebase Data Connect For Flutter
How to use Firebase Data Connect For Flutter
 
Introduction of Cybersecurity with OSS at Code Europe 2024
Introduction of Cybersecurity with OSS  at Code Europe 2024Introduction of Cybersecurity with OSS  at Code Europe 2024
Introduction of Cybersecurity with OSS at Code Europe 2024
 
Skybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoptionSkybuffer SAM4U tool for SAP license adoption
Skybuffer SAM4U tool for SAP license adoption
 
Artificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopmentArtificial Intelligence for XMLDevelopment
Artificial Intelligence for XMLDevelopment
 
Building Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and MilvusBuilding Production Ready Search Pipelines with Spark and Milvus
Building Production Ready Search Pipelines with Spark and Milvus
 
Project Management Semester Long Project - Acuity
Project Management Semester Long Project - AcuityProject Management Semester Long Project - Acuity
Project Management Semester Long Project - Acuity
 
National Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practicesNational Security Agency - NSA mobile device best practices
National Security Agency - NSA mobile device best practices
 
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing InstancesEnergy Efficient Video Encoding for Cloud and Edge Computing Instances
Energy Efficient Video Encoding for Cloud and Edge Computing Instances
 
UI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentationUI5 Controls simplified - UI5con2024 presentation
UI5 Controls simplified - UI5con2024 presentation
 
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdfUnlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
Unlock the Future of Search with MongoDB Atlas_ Vector Search Unleashed.pdf
 
Monitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdfMonitoring and Managing Anomaly Detection on OpenShift.pdf
Monitoring and Managing Anomaly Detection on OpenShift.pdf
 
WeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation TechniquesWeTestAthens: Postman's AI & Automation Techniques
WeTestAthens: Postman's AI & Automation Techniques
 
Choosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptxChoosing The Best AWS Service For Your Website + API.pptx
Choosing The Best AWS Service For Your Website + API.pptx
 

java.lang.String Class

  • 1. java.lang.String class In Java a String is an object of class java.lang.String and we can make the string objects by calling String constructors. The constructors of java.lang.String classes are overloaded some of them are Creating an empty String String s = new String(); Creating a string with character array String fromCharArray = new String(char[] arr); Creating a string from character array with specified index and number of characters String fromCharArray = new String(char[], int startIndex, int numberOfCharacters); Creating a string from another string String copy = new String(String s);
  • 2. Methods of java.lang.String class length() The method length is used to find the length of a String object. Declaration public int length(); Usage String s = “Alex Vipul Verma”; int len = s.length(); toString() The method toString() is an instance method of Object class and overridden by most of the classes in Java API. It is used to convert any reference data type into String for readable from Declaration public String toString(); Usage Object ob = new Object(); String s = ob.toString();
  • 3. getBytes() The method getBytes() is used to create a byte array from the String with the ASCII values of individual characters Declaration public byte[] getBytes(); Usage String s = “ABCD”; byte[] arr = new byte[s.length()]; arr = s.getBytes(); Here the array arr is generated as byte arr = {65, 66, 67, 68}; toCharArray() The method toCharArray() is similar to getBytes(). The method getBytes() generates the byte type array and char Array generates char type array Declaration public char[] toCharArray(); Usage String s = “Hello!”; char[] arr = new char[s.length]; arr = s.toCharArray(); Here the character array arr is generated as char arr = {‘h’, ‘e’, ‘l’, ‘l’, ‘o’, ‘!’};
  • 4. equals() and equalsIgnoreCase() The method equals() is used to check the equality of two given strings. It returns true if the strings are equal. equalsIgnoreCase() is similar to equals() but it ignore the cases of strings Declaration public boolean equals(String s); public boolean equalsIgnoreCase(String s); Usage boolean result1 = “Alex”.equals(“Alex”); boolean result2 = “Hello”.equals(“HELLO”); startsWith() and endsWith() These two methods are overloaded. They are used to check whether a String is starting (or ending) with specified character or NOT Declaration public boolean startsWith(char ch); public boolean startsWith(String s); public boolean endsWith(char ch); public boolean startsWith(String s);
  • 5. 
 charAt(index) The method charAt() is used to find the character at the specified index from a String Declaration public char charAt(int index); Usage String s = “Alex Vipul Verma”; char ch = s.charAt(10); indexOf() and lastIndexOf() These two methods are also overloaded to take string and character type parameter. They are used to get the index of specified character or string into the existing string. They return -1 if the argument did NOT found into the calling String. Declaration public int indexOf(char ch); public int indexOf(String s); public int lastIndexOf(char ch); public int lastIndexOf(String s);
  • 6. substring() substring() is an overloaded method. Used to create a substring from another string. It is helpful to obtain a copy of string with the specified number of characters and starting index Declaration public String substring(int startIndex); public String substring(int startIndex, endIndex); trim() The method trim() is used to remove the unnecessary whitespaces from a given string. Declaration public String trim(); toUpperCase() and toLowerCase() These two methods are used to convert all the characters of a string to uppercase or lowercase. The String objects are immutable so they do NOT modify the existing String but they return a copy of modified String. Declaration public String toUpperCase(); public String toLowerCase();