SlideShare a Scribd company logo
Programming in Java
Lecture 12: String Handling
Introduction
• Every string we create is actually an object of type String.
• String constants are actually String objects.
• Example:
System.out.println("This is a String, too");
• Objects of type String are immutable i.e. once a String object is
created, its contents cannot be altered.
String
Constant
Why String is Immutable or Final?
• String has been widely used as parameter for many java classes
e.g.
for opening network connection we can pass hostname and port
number as string ,
• we can pass database URL as string for opening database
connection,
• we can open any file in Java by passing name of file as
argument to File I/O classes.
• In case if String is not immutable , this would lead serious
security threat , means some one can access to any file for
which he has authorization and then can change the file name
either deliberately or accidentally and gain access of those file.
Introduction
• In java, four predefined classes are provided that either
represent strings or provide functionality to manipulate them.
Those classes are:
• String
• StringBuffer
• StringBuilder
• StringTokenizer
 String, StringBuffer, and StringBuilder classes are defined in java.lang package and
all are final.
 All of them implement the CharSequence interface.
Why String Handling?
String handling is required to perform following operations on
some string:
• compare two strings
• search for a substring
• concatenate two strings
• change the case of letters within a string
Creating String objects
class StringDemo
{
public static void main(String args[])
{
String strOb1 = “Ravi";
String strOb2 = “LPU";
String strOb3 = strOb1 + " and " + strOb2;
System.out.println(strOb1);
System.out.println(strOb2);
System.out.println(strOb3);
}
}
String Class
String Constructor:
public String ()
public String (String)
public String (char [])
public String (byte [])
public String (char [], int offset, int no_of_chars)
public String (byte [], int offset, int no_of _bytes)
Examples
char [] a = {'c', 'o', 'n', 'g', 'r', 'a', 't', 's'};
byte [] b = {82, 65, 86, 73, 75, 65, 78, 84};
String s1 = new String (a); System.out.println(s1);
String s2 = new String (a, 1,5); System.out.println(s2);
String s3 = new String (s1); System.out.println(s3);
String s4 = new String (b); System.out.println(s4);
String s5 = new String (b, 4, 4); System.out.println(s5);
String Concatenation
• Concatenating Strings:
String age = "9";
String s = "He is " + age + " years old.";
System.out.println(s);
• Using concatenation to prevent long lines:
String longStr = “This could have been” +
“a very long line that would have” +
“wrapped around. But string”+
“concatenation prevents this.”;
System.out.println(longStr);
String Concatenation with Other Data Types
• We can concatenate strings with other types of data.
Example:
int age = 9;
String s = "He is " + age + " years old.";
System.out.println(s);
Methods of String class
• String Length:
length() returns the length of the string i.e. number of characters.
int length()
Example:
char chars[] = { 'a', 'b', 'c' };
String s = new String(chars);
System.out.println(s.length());
concat( ): used to concatenate two strings.
String concat(String str)
• This method creates a new object that contains the invoking string
with the contents of str appended to the end.
• concat( ) performs the same function as +.
Example:
String s1 = "one"; String s2 = s1.concat("two");
• It generates the same result as the following sequence:
String s1 = "one"; String s2 = s1 + "two";
Character Extraction
• charAt(): used to obtain the character from the specified index from
a string.
public char charAt (int index);
Example:
char ch;
ch = "abc".charAt(1);
Methods Cont…
• getChars(): used to obtain set of characters from the string.
public void getChars(int start_index, int end_index, char[], int
offset)
Example: String s = “KAMAL”;
char b[] = new char [10];
b[0] = ‘N’; b[1] = ‘E’;
b[2] = ‘E’; b[3] = ‘L’;
s.getChars(0, 4, b, 4);
System.out.println(b);
Methods Cont…
• toCharArray(): returns a character array initialized by the contents
of the string.
public char [] toCharArray();
Example: String s = “India”;
char c[] = s.toCharArray();
for (int i=0; i<c.length; i++)
{
if (c[i]>= 65 && c[i]<=90)
c[i] += 32;
System.out.print(c[i]);
}
String Comparison
• equals(): used to compare two strings for equality.
Comparison is case-sensitive.
public boolean equals (Object str)
• equalsIgnoreCase( ): To perform a comparison that ignores case differences.
Note:
• This method is defined in Object class and overridden in String class.
• equals(), in Object class, compares the value of reference not the content.
• In String class, equals method is overridden for content-wise comparison of
two strings.
Example
class equalsDemo {
public static void main(String args[]) {
String s1 = "Hello";
String s2 = "Hello";
String s3 = "Good-bye";
String s4 = "HELLO";
System.out.println(s1 + " equals " + s2 + " -> " +
s1.equals(s2));
System.out.println(s1 + " equals " + s3 + " -> " +
s1.equals(s3));
System.out.println(s1 + " equals " + s4 + " -> " +
s1.equals(s4));
System.out.println(s1 + " equalsIgnoreCase " + s4 + " -> “
+s1.equalsIgnoreCase(s4));
}
}
String Comparison
• startsWith( ) and endsWith( ):
• The startsWith( ) method determines whether a given String
begins with a specified string.
• Conversely, endsWith( ) determines whether the String in question
ends with a specified string.
boolean startsWith(String str)
boolean endsWith(String str)
String Comparison
compareTo( ):
• A string is less than another if it comes before the other in dictionary
order.
• A string is greater than another if it comes after the other in
dictionary order.
int compareTo(String str)
Example
class SortString {
static String arr[] = {"Now", "is", "the", "time", "for", "all", "good", "men",
"to", "come", "to", "the", "aid", "of", "their", "country"};
public static void main(String args[]) {
for(int j = 0; j < arr.length; j++) {
for(int i = j + 1; i < arr.length; i++) {
if(arr[i].compareTo(arr[j]) < 0) {
String t = arr[j];
arr[j] = arr[i];
arr[i] = t;
}
}
System.out.println(arr[j]);
}
}
}
Searching Strings
• The String class provides two methods that allow us to search a string
for a specified character or substring:
indexOf( ): Searches for the first occurrence of a character or substring.
int indexOf(int ch)
lastIndexOf( ): Searches for the last occurrence of a character or
substring.
int lastIndexOf(int ch)
• To search for the first or last occurrence of a substring, use
int indexOf(String str)
int lastIndexOf(String str)
• We can specify a starting point for the search using these forms:
int indexOf(int ch, int startIndex)
int lastIndexOf(int ch, int startIndex)
int indexOf(String str, int startIndex)
int lastIndexOf(String str, int startIndex)
• Here, startIndex specifies the index at which point the search begins.
• For indexOf( ), the search runs from startIndex to the end of the
string.
• For lastIndexOf( ), the search runs from startIndex to zero.
Example
class indexOfDemo {
public static void main(String args[]) {
String s = "Now is the time for all good men " +
"to come to the aid of their country.";
System.out.println(s);
System.out.println("indexOf(t) = " + s.indexOf('t'));
System.out.println("lastIndexOf(t) = " + s.lastIndexOf('t'));
System.out.println("indexOf(the) = " + s.indexOf("the"));
System.out.println("lastIndexOf(the) = " + s.lastIndexOf("the"));
System.out.println("indexOf(t, 10) = " + s.indexOf('t', 10));
System.out.println("lastIndexOf(t, 60) = " + s.lastIndexOf('t', 60));
System.out.println("indexOf(the, 10) = " + s.indexOf("the", 10));
System.out.println("lastIndexOf(the, 60) = " + s.lastIndexOf("the", 60));
}
}
Modifying a String
• Because String objects are immutable, whenever we want to modify a
String, it will construct a new copy of the string with modifications.
• substring(): used to extract a part of a string.
public String substring (int start_index)
public String substring (int start_index, int end_index)
Example: String s = “ABCDEFG”;
String t = s.substring(2); System.out.println (t);
String u = s.substring (1, 4); System.out.println (u);
Note: Substring from start_index to end_index-1 will be returned.
replace( ): The replace( ) method has two forms.
• The first replaces all occurrences of one character in the invoking string with
another character. It has the following general form:
String replace(char original, char replacement)
• Here, original specifies the character to be replaced by the character specified by
replacement.
Example: String s = "Hello".replace('l', 'w');
• The second form of replace( ) replaces one character sequence with another. It
has this general form:
String replace(CharSequence original, CharSequence replacement)
trim( )
• The trim( ) method returns a copy of the invoking string from which
any leading and trailing whitespace has been removed.
String trim( )
Example:
String s = " Hello World ".trim();
This puts the string “Hello World” into s.
Changing the Case of Characters Within a String
toLowerCase() & toUpperCase()
• Both methods return a String object that contains the uppercase
or lowercase equivalent of the invoking String.
String toLowerCase( )
String toUpperCase( )
L13 string handling(string class)

More Related Content

PPTX
Class, object and inheritance in python
PPTX
Sax parser
PDF
Immutable vs mutable data types in python
PPTX
Handling of character strings C programming
PDF
Python functions
PDF
Variables & Data Types In Python | Edureka
PDF
Python strings
PPTX
Java String Handling
Class, object and inheritance in python
Sax parser
Immutable vs mutable data types in python
Handling of character strings C programming
Python functions
Variables & Data Types In Python | Edureka
Python strings
Java String Handling

What's hot (20)

PPS
String and string buffer
PPTX
Introduction to numpy Session 1
DOCX
DAA Lab File C Programs
PPTX
Java string handling
DOCX
Data Structures Using C Practical File
PPT
Strings in c
PPT
Python ppt
PPT
C++ Data Structure PPT.ppt
PPTX
Python strings presentation
PPTX
15. Streams Files and Directories
PPTX
String Manipulation in Python
PDF
Data visualization in Python
PDF
List , tuples, dictionaries and regular expressions in python
PPTX
MatplotLib.pptx
PDF
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
PPTX
Python basics
PPSX
Programming with Python
PPTX
PYTHON OBJECTS - Copy.pptx
PPS
Wrapper class
PDF
Python libraries
String and string buffer
Introduction to numpy Session 1
DAA Lab File C Programs
Java string handling
Data Structures Using C Practical File
Strings in c
Python ppt
C++ Data Structure PPT.ppt
Python strings presentation
15. Streams Files and Directories
String Manipulation in Python
Data visualization in Python
List , tuples, dictionaries and regular expressions in python
MatplotLib.pptx
Python Functions Tutorial | Working With Functions In Python | Python Trainin...
Python basics
Programming with Python
PYTHON OBJECTS - Copy.pptx
Wrapper class
Python libraries
Ad

Viewers also liked (20)

PPT
PDF
Arrays string handling java packages
PPT
String handling session 5
PPTX
Indian Property Lawyers .com - How It Works
PPTX
String java
PDF
April 2014
PPTX
Open and Close Door ppt
PPTX
java Applet Introduction
PPTX
Java String
PPT
String Handling
PPT
Java Applet
PPTX
applet using java
PDF
ITFT- Applet in java
PPT
Java applet
PPTX
L18 applets
PDF
Java Applet and Graphics
PDF
String handling(string class)
PPTX
Strings in Java
PPT
Java: Java Applets
Arrays string handling java packages
String handling session 5
Indian Property Lawyers .com - How It Works
String java
April 2014
Open and Close Door ppt
java Applet Introduction
Java String
String Handling
Java Applet
applet using java
ITFT- Applet in java
Java applet
L18 applets
Java Applet and Graphics
String handling(string class)
Strings in Java
Java: Java Applets
Ad

Similar to L13 string handling(string class) (20)

PPTX
Java string handling
PPSX
String and string manipulation x
PPT
String and string manipulation
PPT
Charcater and Strings.ppt Charcater and Strings.ppt
PPTX
C-Arrays & Strings (computer programming).pptx
PPTX
Module-2_Strings concepts in c programming
PPTX
String in java, string constructors and operations
PPTX
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
PPTX
L14 string handling(string buffer class)
PPTX
Programing with java for begniers .pptx
PPTX
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
PPTX
Computer programming 2 Lesson 12
PPTX
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
PPTX
16 strings-and-text-processing-120712074956-phpapp02
PPTX
Arrays in java
PPTX
07. Java Array, Set and Maps
PPTX
programming for problem solving using C-STRINGSc
PPTX
UNIT 4C-Strings.pptx for c language and basic knowledge
PPTX
Arrays & Strings.pptx
PPT
String manipulation techniques like string compare copy
Java string handling
String and string manipulation x
String and string manipulation
Charcater and Strings.ppt Charcater and Strings.ppt
C-Arrays & Strings (computer programming).pptx
Module-2_Strings concepts in c programming
String in java, string constructors and operations
String.pptxihugyftgrfxdf bnjklihugyfthfgxvhbjihugyfthcgxcgvjhbkipoihougyfctgf...
L14 string handling(string buffer class)
Programing with java for begniers .pptx
21CS642 Module 3 Strings PPT.pptx VI SEM CSE
Computer programming 2 Lesson 12
3.1 STRINGS (1) java jksdbkjdbsjsef.pptx
16 strings-and-text-processing-120712074956-phpapp02
Arrays in java
07. Java Array, Set and Maps
programming for problem solving using C-STRINGSc
UNIT 4C-Strings.pptx for c language and basic knowledge
Arrays & Strings.pptx
String manipulation techniques like string compare copy

More from teach4uin (20)

PPTX
Controls
PPT
validation
PPT
validation
PPT
Master pages
PPTX
.Net framework
PPT
Scripting languages
PPTX
Css1
PPTX
Code model
PPT
Asp db
PPTX
State management
PPT
security configuration
PPT
static dynamic html tags
PPT
static dynamic html tags
PPTX
New microsoft office power point presentation
PPT
.Net overview
PPT
Stdlib functions lesson
PPT
enums
PPT
memory
PPT
array
PPT
storage clas
Controls
validation
validation
Master pages
.Net framework
Scripting languages
Css1
Code model
Asp db
State management
security configuration
static dynamic html tags
static dynamic html tags
New microsoft office power point presentation
.Net overview
Stdlib functions lesson
enums
memory
array
storage clas

Recently uploaded (20)

PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PPTX
1. Introduction to Computer Programming.pptx
PPTX
Big Data Technologies - Introduction.pptx
PDF
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
PPTX
Machine Learning_overview_presentation.pptx
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Getting Started with Data Integration: FME Form 101
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PPTX
Group 1 Presentation -Planning and Decision Making .pptx
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
SOPHOS-XG Firewall Administrator PPT.pptx
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PPTX
Programs and apps: productivity, graphics, security and other tools
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
1. Introduction to Computer Programming.pptx
Big Data Technologies - Introduction.pptx
Video forgery: An extensive analysis of inter-and intra-frame manipulation al...
Machine Learning_overview_presentation.pptx
Spectral efficient network and resource selection model in 5G networks
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
MYSQL Presentation for SQL database connectivity
Mobile App Security Testing_ A Comprehensive Guide.pdf
Per capita expenditure prediction using model stacking based on satellite ima...
Getting Started with Data Integration: FME Form 101
Diabetes mellitus diagnosis method based random forest with bat algorithm
Group 1 Presentation -Planning and Decision Making .pptx
20250228 LYD VKU AI Blended-Learning.pptx
SOPHOS-XG Firewall Administrator PPT.pptx
MIND Revenue Release Quarter 2 2025 Press Release
“AI and Expert System Decision Support & Business Intelligence Systems”
Programs and apps: productivity, graphics, security and other tools
Advanced methodologies resolving dimensionality complications for autism neur...

L13 string handling(string class)

  • 1. Programming in Java Lecture 12: String Handling
  • 2. Introduction • Every string we create is actually an object of type String. • String constants are actually String objects. • Example: System.out.println("This is a String, too"); • Objects of type String are immutable i.e. once a String object is created, its contents cannot be altered. String Constant
  • 3. Why String is Immutable or Final? • String has been widely used as parameter for many java classes e.g. for opening network connection we can pass hostname and port number as string , • we can pass database URL as string for opening database connection, • we can open any file in Java by passing name of file as argument to File I/O classes. • In case if String is not immutable , this would lead serious security threat , means some one can access to any file for which he has authorization and then can change the file name either deliberately or accidentally and gain access of those file.
  • 4. Introduction • In java, four predefined classes are provided that either represent strings or provide functionality to manipulate them. Those classes are: • String • StringBuffer • StringBuilder • StringTokenizer  String, StringBuffer, and StringBuilder classes are defined in java.lang package and all are final.  All of them implement the CharSequence interface.
  • 5. Why String Handling? String handling is required to perform following operations on some string: • compare two strings • search for a substring • concatenate two strings • change the case of letters within a string
  • 6. Creating String objects class StringDemo { public static void main(String args[]) { String strOb1 = “Ravi"; String strOb2 = “LPU"; String strOb3 = strOb1 + " and " + strOb2; System.out.println(strOb1); System.out.println(strOb2); System.out.println(strOb3); } }
  • 7. String Class String Constructor: public String () public String (String) public String (char []) public String (byte []) public String (char [], int offset, int no_of_chars) public String (byte [], int offset, int no_of _bytes)
  • 8. Examples char [] a = {'c', 'o', 'n', 'g', 'r', 'a', 't', 's'}; byte [] b = {82, 65, 86, 73, 75, 65, 78, 84}; String s1 = new String (a); System.out.println(s1); String s2 = new String (a, 1,5); System.out.println(s2); String s3 = new String (s1); System.out.println(s3); String s4 = new String (b); System.out.println(s4); String s5 = new String (b, 4, 4); System.out.println(s5);
  • 9. String Concatenation • Concatenating Strings: String age = "9"; String s = "He is " + age + " years old."; System.out.println(s); • Using concatenation to prevent long lines: String longStr = “This could have been” + “a very long line that would have” + “wrapped around. But string”+ “concatenation prevents this.”; System.out.println(longStr);
  • 10. String Concatenation with Other Data Types • We can concatenate strings with other types of data. Example: int age = 9; String s = "He is " + age + " years old."; System.out.println(s);
  • 11. Methods of String class • String Length: length() returns the length of the string i.e. number of characters. int length() Example: char chars[] = { 'a', 'b', 'c' }; String s = new String(chars); System.out.println(s.length());
  • 12. concat( ): used to concatenate two strings. String concat(String str) • This method creates a new object that contains the invoking string with the contents of str appended to the end. • concat( ) performs the same function as +. Example: String s1 = "one"; String s2 = s1.concat("two"); • It generates the same result as the following sequence: String s1 = "one"; String s2 = s1 + "two";
  • 13. Character Extraction • charAt(): used to obtain the character from the specified index from a string. public char charAt (int index); Example: char ch; ch = "abc".charAt(1);
  • 14. Methods Cont… • getChars(): used to obtain set of characters from the string. public void getChars(int start_index, int end_index, char[], int offset) Example: String s = “KAMAL”; char b[] = new char [10]; b[0] = ‘N’; b[1] = ‘E’; b[2] = ‘E’; b[3] = ‘L’; s.getChars(0, 4, b, 4); System.out.println(b);
  • 15. Methods Cont… • toCharArray(): returns a character array initialized by the contents of the string. public char [] toCharArray(); Example: String s = “India”; char c[] = s.toCharArray(); for (int i=0; i<c.length; i++) { if (c[i]>= 65 && c[i]<=90) c[i] += 32; System.out.print(c[i]); }
  • 16. String Comparison • equals(): used to compare two strings for equality. Comparison is case-sensitive. public boolean equals (Object str) • equalsIgnoreCase( ): To perform a comparison that ignores case differences. Note: • This method is defined in Object class and overridden in String class. • equals(), in Object class, compares the value of reference not the content. • In String class, equals method is overridden for content-wise comparison of two strings.
  • 17. Example class equalsDemo { public static void main(String args[]) { String s1 = "Hello"; String s2 = "Hello"; String s3 = "Good-bye"; String s4 = "HELLO"; System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2)); System.out.println(s1 + " equals " + s3 + " -> " + s1.equals(s3)); System.out.println(s1 + " equals " + s4 + " -> " + s1.equals(s4)); System.out.println(s1 + " equalsIgnoreCase " + s4 + " -> “ +s1.equalsIgnoreCase(s4)); } }
  • 18. String Comparison • startsWith( ) and endsWith( ): • The startsWith( ) method determines whether a given String begins with a specified string. • Conversely, endsWith( ) determines whether the String in question ends with a specified string. boolean startsWith(String str) boolean endsWith(String str)
  • 19. String Comparison compareTo( ): • A string is less than another if it comes before the other in dictionary order. • A string is greater than another if it comes after the other in dictionary order. int compareTo(String str)
  • 20. Example class SortString { static String arr[] = {"Now", "is", "the", "time", "for", "all", "good", "men", "to", "come", "to", "the", "aid", "of", "their", "country"}; public static void main(String args[]) { for(int j = 0; j < arr.length; j++) { for(int i = j + 1; i < arr.length; i++) { if(arr[i].compareTo(arr[j]) < 0) { String t = arr[j]; arr[j] = arr[i]; arr[i] = t; } } System.out.println(arr[j]); } } }
  • 21. Searching Strings • The String class provides two methods that allow us to search a string for a specified character or substring: indexOf( ): Searches for the first occurrence of a character or substring. int indexOf(int ch) lastIndexOf( ): Searches for the last occurrence of a character or substring. int lastIndexOf(int ch) • To search for the first or last occurrence of a substring, use int indexOf(String str) int lastIndexOf(String str)
  • 22. • We can specify a starting point for the search using these forms: int indexOf(int ch, int startIndex) int lastIndexOf(int ch, int startIndex) int indexOf(String str, int startIndex) int lastIndexOf(String str, int startIndex) • Here, startIndex specifies the index at which point the search begins. • For indexOf( ), the search runs from startIndex to the end of the string. • For lastIndexOf( ), the search runs from startIndex to zero.
  • 23. Example class indexOfDemo { public static void main(String args[]) { String s = "Now is the time for all good men " + "to come to the aid of their country."; System.out.println(s); System.out.println("indexOf(t) = " + s.indexOf('t')); System.out.println("lastIndexOf(t) = " + s.lastIndexOf('t')); System.out.println("indexOf(the) = " + s.indexOf("the")); System.out.println("lastIndexOf(the) = " + s.lastIndexOf("the")); System.out.println("indexOf(t, 10) = " + s.indexOf('t', 10)); System.out.println("lastIndexOf(t, 60) = " + s.lastIndexOf('t', 60)); System.out.println("indexOf(the, 10) = " + s.indexOf("the", 10)); System.out.println("lastIndexOf(the, 60) = " + s.lastIndexOf("the", 60)); } }
  • 24. Modifying a String • Because String objects are immutable, whenever we want to modify a String, it will construct a new copy of the string with modifications. • substring(): used to extract a part of a string. public String substring (int start_index) public String substring (int start_index, int end_index) Example: String s = “ABCDEFG”; String t = s.substring(2); System.out.println (t); String u = s.substring (1, 4); System.out.println (u); Note: Substring from start_index to end_index-1 will be returned.
  • 25. replace( ): The replace( ) method has two forms. • The first replaces all occurrences of one character in the invoking string with another character. It has the following general form: String replace(char original, char replacement) • Here, original specifies the character to be replaced by the character specified by replacement. Example: String s = "Hello".replace('l', 'w'); • The second form of replace( ) replaces one character sequence with another. It has this general form: String replace(CharSequence original, CharSequence replacement)
  • 26. trim( ) • The trim( ) method returns a copy of the invoking string from which any leading and trailing whitespace has been removed. String trim( ) Example: String s = " Hello World ".trim(); This puts the string “Hello World” into s.
  • 27. Changing the Case of Characters Within a String toLowerCase() & toUpperCase() • Both methods return a String object that contains the uppercase or lowercase equivalent of the invoking String. String toLowerCase( ) String toUpperCase( )