0% found this document useful (0 votes)
13 views21 pages

Untitled

String is a sequence of characters that can be represented and manipulated as objects in Java using the String class in the java.lang package. There are several ways to create String objects including assigning a string value within double quotes to a variable, using the String constructor and passing a value, or creating a character array and passing it to the String constructor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views21 pages

Untitled

String is a sequence of characters that can be represented and manipulated as objects in Java using the String class in the java.lang package. There are several ways to create String objects including assigning a string value within double quotes to a variable, using the String constructor and passing a value, or creating a character array and passing it to the String constructor.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

String is a sequence of characters.

In the Java programming language, strings are


objects.

Java provides a class called “String” in


“java.lang” package to create and manipulate
strings.

The string value must be represented in “ ”


(double cotes).
Direct way to create a string
Variable
name

Class name (Data type) defined


Variable
in
Java.lang value
Another way to create a string

Variable String class


name Constructor

Class name (Data new Variable


type) defined in operator value
Java.lang
Another way to create a string

Here, first we create a character array and pass that


array as argument to the string class constructor
This method returns a integer which is equal to total number
of Characters present in a string object.

For example, the string length of "Note Book" is 9 including


the space character.
String concatenation is the operation of joining two string objects end
to end.
For example, the concatenation of two strings "Foot” and "ball” is
"Football“ 
String concatenation can also be done using + operator
For example, the concatenation of two strings "Foot” and "ball” is
"Football“ as follows 
This method takes an index as a parameter and returns the character
that is present at that index of the string.
The equals is used to compare two Strings and states whether they are
equal or not.
The equals IgnoreCase is used to compare two Strings by ignoring
letter case and states whether they are equal or not.
The startsWith accepts a string and checks whether the invoking string
starts with the given string or not.
Note: startsWith method also have one more form as follows
The endsWith accepts a string and determines whether the invoking
string ends with the given string or not. 
The String class provides 2 methods for searching a string. 

indexOf() : Searches for the first occurrence of a character or


substring.

lastIndexOf() : Searches for the last occurrence of a character or


substring
The substring method can be used to extract some characters from
the String. 
This method comes in two forms
The replace() is used to replace a character or a sequence of characters
of an invoking string with a desired character or set of characters 
trim is used to trim/remove whitespace from the beginning and the end of
the string that invoked this method.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy