Strings
Strings
IN JAVA
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:-
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”.