Download presentation
Presentation is loading. Please wait.
1
Unit-2 Objects and Classes
String Class
2
String Class A string is a sequence of characters.
In many languages, strings are treated as an array of characters, but in Java a string is an object. The String class has 11 constructors and more than 40 methods for manipulating strings.
3
Constructing a String
4
Immutable Strings and Interned Strings
5
String Comparisons
6
String Comparisons(Cont.)
Using equals Function:
7
String Comparisons(Cont.)
Using compare To Function:
8
Program(Equal to & Compare TO)
9
Program(regionMatches() )
10
Program (endWith)
11
Program (startWith)
12
String Length, Characters, and Combining Strings
The String class provides the methods for obtaining length, retrieving individual characters, and concatenating strings.
13
Program
14
Obtaining Substrings You can also obtain a substring from a string using the substring method in the String class.
15
Example
16
Converting, Replacing, and Splitting Strings
The String class provides the methods for converting, replacing, and splitting strings, as shown in Figure.
17
Program
18
Example(Split () )
19
String Matching
20
Finding a Character or a Substring in a String
The String class provides several overloaded indexOf and lastIndexOf methods to find a character or a substring in a string.
21
Program
22
Conversion between Strings and Arrays
23
Formatting Strings
24
Converting Characters and Numeric Values to Strings
There are several overloaded versions of the valueOf method that can be used to convert a character and numeric values to strings with different parameter types, char, double, long, int, and float.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.