0% found this document useful (0 votes)
10 views10 pages

Strings

Uploaded by

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

Strings

Uploaded by

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

Strings in Java

By: Anagha and Thrayee


Introduction to STRINGS
A string is a sequence of characters used to represent text. Strings are commonly
used for storing and manipulating textual data in computer programs. They can
be manipulated using various operations like concatenation, substring extraction,
and comparison.
Strings are utilized in web development for constructing URLs, handling form
data, processing input from web forms, and generating dynamic content. Strings
are immutable in many programming languages.
Functions of STRINGS
Functions of strings :
1. length()
2. charAt(int n)
3. indexOf(char ch)
4. trim()
5. concat(String str)
6. replace(char oldChar, char newChar)
● This function returns the number of
characters present in a string , including
length() ●
whitespaces.
Its return type is ‘int’

SYNTAX : String_variable.length()

CODE :

OUTPUT :
● This function returns the characters
present at the specified position(index) in
charAt(int n) a string.
● Its return type is ‘char’

SYNTAX : String_variable.charAt(index
position)

CODE :

OUTPUT :
● This function returns the position(index)

indexOf(char ch)
of the first occurrence of a specified
character in a [Link] the character is not
present in the string, the method will
return -1.
● Its return type is ‘int’

SYNTAX : String_variable.indexOf(char)

CODE :

OUTPUT :
● This function removes blank spaces from

trim()
the beginning or end of a string.
● Its return type is ‘String’.

SYNTAX:

String_variable.trim();

CODE:

OUTPUT:
● This function concatenates two strings
together to produce a new string.
concat(String str) ● Its return type is ‘String’.
SYNTAX:
String_Variable_1.concat(String_Variable_2);
CODE:

OUTPUT:
● This function replaces all occurrences of

Replace(char oldChar,
a particular character or a group of
characters with another character or
char new char) ●
group of characters in the string.
Its return type is ‘String’.
SYNTAX:
String_Variable.replace(char oldChar, char
newChar);
CODE:

OUTPUT:
Thank you

You might also like