0% found this document useful (0 votes)
12 views20 pages

Strings

Uploaded by

divanshiagg1768
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)
12 views20 pages

Strings

Uploaded by

divanshiagg1768
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
You are on page 1/ 20

STRINGS

IN JAVA

PRESENTED BY - DIVANSHI AGGARWAL


2
OUTLINE
what is string? comparison charat && contain

initialising a string substring replace

string operation lengthofstring tochararray

concatenation uppercase & indexof


lowercase
others
thank you
3
WHAT IS STRING?
String are sequence of characters which
are widely used in java.
In Java programming language strings are
treated as Objects.
Java Platform provide string class to create
and manipulate strings.
4
STRING
String - objective or They are immutable
primitive? Which means once a string
String could be considered as object is created it cant be
primitive but they are not. modified later.
As they are actually made up of For mutable string in java we
array of char primitive. use stringBuffer &
stringBuilder classes.
an object which cant be alter are immutable.
strings,int,char,short,float,double all are classes objects are
immutable.
5
CREATING A STRING
There are Two ways to create string:-

1 BY LITERAL METHOD:-
EX- String name = “welcome”

By NEW Keyword
2
ex- String name = new String(“welcome”)
EXAMPLE
6
STRINGS METHOD
String methods operate on Java strings. They can be used to
find the new length of string , or converting to uppercase etc.
string concatenation
string comparison
length of string
to lowercase()
to uppercase
substring
replace
8
STRING CONCATENATION
9
STRING COMPARISON
String comparison can be done in 3 ways:-

using equals( ) method


using == operator
by compareTo method
10
SUBSTRING
It is a part of string is known as
substring. It is subset of string.

we can get substringfrom the given


string by 2 methods:
1) publicString substring( int startIndex):

2) publicString substring( int startIndex


, int endIndex):
11
LENGTH OF SUBSTRING
In Java string.length( ) method find length of string.
it returns count of total number of character.
12
To LowerCase() & to UpperCase()

to Lowercase() :- return string in lowercase


to Upeercase() :- convert all character of string in upper case

will return:-

//to lowercase
my name is salman

/to uppercase
MY NAME IS SALMAN.
13
charAt() & contains()
charAt() :- return a character value at given index where index
starts from 0
contains() :- its a boolean expression where it searches the
sequence of character in string. return true , if string is present
14
REPLACE()
string.replace(r,p) :- returns a string replacing all old char to new char sequence,
15
toCharArray()
toCharArray() :- converts string into character array.
16
INDEXOF()
returns index of given
indexof() :- character value or
substring. if it is not
found, it return -1. index
starts from 0.
17
& OTHERS ARE:-
string name = “salman”;
name.startswith(“sa”) :- return true if name of string starts with “sa” from the
1 string = “salman”.

name.endswith(“mon”) :- returns false


2 &
name.equals(“khan”):- return false in this case. as both strings are not equal.

name.lastindexof(“l”):-return 3 in this case.


3
18
THANK YOU

You might also like