0% found this document useful (0 votes)
2 views51 pages

Java String Handling Techniques

Uploaded by

julanta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views51 pages

Java String Handling Techniques

Uploaded by

julanta
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

MODULE-2

AGENDA 2

String Handling : • Changing the Case of


• The String Constructors, Characters Within a String,
• String Length, • joining strings,
• Special String Operations, • Additional String Methods,
• Character Extraction, • StringBuffer,
• String Comparison, • StringBuilder
• Searching Strings,
• Modifying a String,
• Data Conversion Using
valueOf( ),
STRING
CONSTRUCTORS
4

JAVA STRING CONSTRUCTORS ALLOWS


US TO CREATE A STRING OBJECT FROM
DIFFERENT TYPE OF ARGUMENTS.
5
6
7
8
STRING LENGTH
10
• How to Find Length of String in Java
• 11
The string length or size means the total number of characters
present in it. In String, all the elements are stored in the form of
characters i.e., “1”, ” “, “_”, etc all are considered as characters.
• Example String: "Geeks For Geeks"
size: 15
12

SPECIAL STRING
OPERATIONS
13

Java String literal is created by using double quotes. For Example


1. String Literals –
String s="javaguides";

2. String Concatenation –
3. String Concatenation 14
15
16
17
18

CHARACTER EXTRACTION
There are several ways by which characters can be
extracted from String class object. String is treated
as an object in Java so we can’t directly access the
characters that comprise a string. For doing this
String class provides various predefined methods.
• charAt() - used to extract a single character at an index. It has
19
following syntax.
Syntax 1 char charAt(int index)
Example 1 class temp Output
2 { l
3 public static void
4 main(String...s)
5 {
6 String str="Hello";
7 char ch=[Link](2);
8 [Link](ch);
9 }
}
20
21

STRING COMPARISON
22

1) By Using equals() Method


• The String class equals() method compares the original content
of the string. It compares values of string for equality. String
class provides the following two methods:
• public boolean equals(Object another) compares this string
to the specified object.
• public boolean equalsIgnoreCase(String
another) compares this string to another string, ignoring case.
23
24
25
26

SEARCHING STRING- STRING


HANDLING IS ONE OF THE MOST ESSENTIAL
CONCEPTS IN JAVA, AND SEARCHING WITHIN
STRINGS IS A COMMON TASK.
27
28
29
30

MODIFYING STRING - STRING


MODIFICATION IS AN ESSENTIAL TASK IN
PROGRAMMING, AND JAVA PROVIDES SEVERAL
METHODS TO PERFORM SUCH OPERATIONS.
WHILE STRINGS IN JAVA ARE IMMUTABLE,
THESE METHODS RETURN NEW STRINGS WITH
THE MODIFICATIONS APPLIED
31
32

\
6. split(String regex)
33
• Splits the string around matches of the given regular
expression.
String str = "Java,Guides";
String[] result = [Link](",");
// Result: ["Java", "Guides"]
34

DATA CONVERSION USING


VALUEOF( )
35
• valueOf() method converts data from its internal form into a
human-readable form. It is a static method that is overloaded
within a string for all of Java’s built-in types so that each type
can be converted properly into a string.
• It is called when a string representation of some other type of
data is needed for example during a concatenation operation.
You can call this method with any data type and get a
reasonable String representation valueOf() returns
[Link], which is the object representative of the
integer.
36
37

CHANGING THE CASE OF


CHARACTERS WITHIN A
STRING
38
39
40

JOINING STRINGS
41
42

ADDITIONAL STRING
METHODS
43
44
45

STRING BUFFER
46
47
48

STRING BUILDER
49
50
THANK
YOU

You might also like