TRNG
S i n g - n _fava sbing is a set
chanadek b u ti k e o t h o r . anquag
stuing a s chaHated
thy nmpliments a s object of type
but in Java Btring
gtning means thing a Bystem dejina
hackage hw a
class in dang
Combarision U classto sthing Callld
stming bull
Sting Coansbuucton-Sbung clas hau
euural Comsbuclör 0 incudsng deault
Consulon.
.StringS nuw Sbung
Stan (ehachl10
24 cha chl_]E 7 ' , ' i ' ,' t
Stustem. eut.println lch);
Sthinglchaehl,nt si,intEn)s
{ 3 , ' , ' T ' , EEJ
eXi_chan chtJ
S i n g S 2nLOSEninglch,1,3)s
Syctekn. out. pintl
("s i + s )
S L, T, E
Stdag obj ).
4Sbing
R;'a A v ' , 'A'}
chax cL]=
St =mu tHng-
Stxing
tung S2 nus So:ing s4);
Sugken.outprintdnls i)s
USyslem.ot.ritln lsa
OUTPUI AaVa
Metheda
tho. ubung à tha no. of
Sing angth-Length e
chabeaclA bresent 0 n
mtax-
chan
int legthL',ip1,'T J
Sbunach)
Sbung S
Sbing nus
dysek.out. printn (s.kengtnh c)
OUTPUI =3
erm.oul.brintloCRITEE longthO):
OUTPUT25
Coneatenalion-She plus oheralo
Sthing
usedoc.alinate the bhiing n 4ava.
Example 20
SEhing
SthinsagLLS
Wysteko.out.brintly(sd
"3
Sthing S
Syghen.out.pnaily tS)
:2
tninaS fie (2t3)
yshm.out-println. (s)3
taing S "Fiu +(23);
Syslem.ouit. paiotln(S)3
t Convexsian.=tasbingC)
dyntax Sbris Yasbingy
example
clasa box
oloubludth,height, depth
box double u dou ble. h, dauble. d)
uwidth =WS
dnpth d
heigut -hs
bubllc Sting toSbing)
l n n dimensiom uuielh + " B4
hught +By" tdapths
class dlumn
bublicstaHe void mainlSIaiag aigs l1)
box bi Mu ibox /o;20, 30s
Sbing s="box "46
ysten out.printin(b)
tn.utpintln_sJs
OUTPUT: dimensíom 10 by 20 by 30
bordimeruion lo b 20 by So
Charateh. Crhahm
char Att) exthace or u t Bingle
chanad fhon gtaing-
yrilas_chax. charAtULint Pi
whu b musE fngeh
be nsn-negaktuu inkÙe
chau
"RLTehar At(1);
ten.oiut.pintln lc)%
UTPUT 1i
Getchass): I we uantto: _efart Wn
more then me chanador fzom
String
yn:-0
void qetthars línt P,int e , chan ttl-
nt s )
Stning S T s 4 damo Mthod
int p 10 e =4s
chan LI =nuw chan.
R=E)S
SgetcharslP, e, 4,0
OU TPUT demo,
Stning Com pauison
eguala O Qnd. 2quals Lqnotese C)
This mothod is ued to Combaxe 8tring eguality.
&untar boolean equals 0bjec to )
hoolean edualalgnoka.Case (Strng S)
methed lompaa 8ting_and oluwn
Équals ara Lamne
T u uhen both th 8tAing
uLith_Bamo Case mcan3 cau dansitue
othuuie alse
EquallgnorCasec)zetns w boh the.
8tiing Nlunn nuu both heiring_arL_
amit s onlyspellbensitiu. inot
Case seniHue
Example
ciass 3imilat
buble statte vofdmainStng ags L1)
bing S4 =RIT"
tHin S2.5 RIT
Stund S3
=
"t"
tin S ="Hutea";
Aseout println (S1.eguals(s2));
ten.Oui.ponn S1.equals (s 3))5
Sn.oul.bollo Sl. equalA(S4)))
ys tem.ou.biiln(SI. ehuallgnotalase.(
C
OUTPUT
false
False
equals OJeHIeS
chaacler nsid
Equals mathod Combare the
a 8ung the Z obeseator tompase Tuuo
obiect VH/ene. to 8e whaother. thy
yO 7D Samenstance
Uclass Comba
public aaic vofd main(Stuig axgs l1)
Sting SL RIT";
2u StanS2MwStdng(sL
ysem.out.mtln (S1. equals(s2).
SYstem.od!biln(SI=='s2)
false
oute
Poge
ég Sttng Si = "Hello"2
Stufn s2
S2 SLS
Sysem. ot.pintln( Si=s 2);
SL
H E D L T EO
0UTPU uR
Sbang Seach.
indexOf ) ::=_IE Escaueh br töut occwanu of
achaKacir 0n uhslung ai
JastIndezO£C) E sdearah-yot ho last_occuram
of charackn on dubskun.
nsv alt Caseesth method
ulusn thr inde mumbex)at which t h
chanactnO Bubsbune uwafound OH HOluhn
fon fatlune.
6ynlan
int inderOf (int_ch ):
int lastlnderOf n t ch)s
eg class domo
bubletabic vnid main(Sing angalI)
SLingS= java is sople "
Sysle out.pritln s.indax0f(a);
Ssttm.out.pintln s.latIndex0fCa"
OUTPUT
odiy a Shingi
aku
Substring(3 We can èxbracta
Substing mcthod
sthing Uusing.
äunax Staing ubsthing(int i
oh bsbnng hat
hat
Thu punna acaps
begainat _indix umben 1 and un
Utohe.end of he gtöng
yntay 2 1
ring SubSbing lint s,inte):
h e t a i n g kitnall l e ehana dlen hom
begining Unde p. Nloz e-
clazS e xtyacE
publiastalio void main(Stbing axgsl
Shing S"RITEE
ystem. out.pintin (s.subSthin
sem0ut.piittn(s.siubSi
OUTFUT
IT
TRINGDoffER mucobl) ehsnae péjLl-
String bull is a pa clasa of stinghat
pHOide much oE_tumeHonalils in Stiho
ISbing class tibesent fixedlongth. imutable
chaacters seguehtein contxase.Sting
Bu presenl Qhowable and. uwitable. 0
ehakaorvequencel lhiu elass ailomalically
makeHODm tDAL addiHonal characlos.
Constuctox
StxengBuffer )
d.SbunglBuffe (nt i
3.Stinsuffor (Sting S)j
Y
Langthl) and Capaciby C
int langth) An
Cabaily
Syntax int cabaikyl )
class buffor
public sta He void mainlstung aHas I) |
PLe
StingBuffo sb=new Staing
Buffen"RI7')
Sem.out. þrintnlsb.kngthO)}
uslen.0ut.pintlnl sb. capoiky
U):
OUTPUT : 3
Not
*JheCapai mothod mado koom
Jor o addi tional chauacken auttomaually
charAt BsetChaAt
nax
cha chaiAtlint i)
yntax
vofo &tChauAt Ent i cha e)
eg8- class chauadlo
public stalic void mainStsúng augs LI
Sbing Buffe sb= neg Stsing Bufter
t Hello ";
System.but.þri ntin(sb.CharAt (t)
sb.setChoAt (I, "I');
Syslem.out.poitkn sb)
USh.setlingth ()
stem.out.htln(sb
Sklem.bul.itln sb. chasAEC))E
OOTPOI:-e
HILL0
abbend)
AEcOmcatenalu the 8bunypany othu
yheo dala fo tha end ot th. d envakiksh
biwobjec
DD
SyntaxStringbuffeu abpend(Sting str)i
SEing Butte appendint i)
elass demo
publie atatfa wofd main Stúng axgs L)
R
Stung S3
int a-40
Stiq utfer sb =nuw SttingBurfe)
=lsb»abpend. ("GE). appéndLS
dystem-Dut-printlnsis s )
OUTPUT S S a4o
Eingent_one sting into
mthod Ínsaut 8 n g a t
anotheeh
n y pecihic no.
Stxing Buffer insextlint i,Sbino
urhntax
inant linti, chan eh)
SbngBuffr
las& domo
bublic 8aic void mainSting ag:)
Stung tfes. sb=now StingBre
ava simble O
Sb.insest (Ns, Fs")
yskm.cut. piatloi(sb)
OUTPUT davasinple.
evenaeO =SE u uLed to_ se tho
chaai uuth in a 3tungBuffe objtct,
class b auk
Rublic. static. void main
Stng augiD
Stu ng Butfe sb =rag
Stingbumo
(" ahd)
yelen.cut.pitlas
Sb teveuet)s
Syslen.out. brintn (sb);
OUTPUT abc
cb
delt)_ and dellaChanAtO
yntax-
J StGngburfe Aaleta int Sin, imtei)
Sbingburffoe delst.chaAt (inti)
.
Ustngdalatu)2 yau can dlit moxa than om
chauhattrom 3tüng
Using
Uing dalatchasAtC) youcan dela a barkcu
chaale ofindex.
class demo
ublio stalic yoid mamstin9 ags L1)2
Sting Buffer sbs neuy String Butfo
java is simp"
Sb.dulit (3,493
dgsem.oulpintn (Sb);
ASh.deletiCharAt (3);
ysken-Dul.println lsb);
UTPUT : java Simble
ava l s Simple
Geblau):- ublate one.&et of
chaodv uith anothor e t ot side.
Sting uffes objet
kyntay
0Stxing Burtfeu xaHlace. lint s , inil e, Stin
Examble
clas& chonge
ublic stajic voio main Stxing augsl 1
Staingburte sh=StangBufte"Ta
Sbeplata(4, 6, "wa
ystm.outtpiiln lsh
OUTPUT q wawhut
2ubstng)
poHtion Oof h ma:thod uns a
8tinguomSbungButter
wns,
yntax .
Sting substúng int s)
Shfng SwStrima
Cxample
clas& demo
bublic stakic void mnSting auas LI)
Stsna Butfeu sb =nau Stxing Butteu
ava is simple")
Sting S
S Sb. cubStaing(s)
dystem.out.þrintkn (s)
S sbsubsting (8,14)
Syskem, out.briottn(s
OUreOT Simble