FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
Java-Programs/String/StringBufferBuilderExamples.java at master · Gawsan/Java-Programs · GitHub
Gawsan
/
Java-Programs
Public
forked from
divScorp/Java-Programs
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
Java-Programs
/
String
/
StringBufferBuilderExamples.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
33 lines (26 loc) · 1.16 KB
Breadcrumbs
Java-Programs
/
String
/
StringBufferBuilderExamples.java
Copy path
File metadata and controls
33 lines (26 loc) · 1.16 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
package
String
;
public
class
StringBufferBuilderExamples
{
public
static
void
main
(
String
[]
args
) {
// StringBuffer and StringBuilder are used when you want to modify
// object values.
StringBuffer
stringbuffer
=
new
StringBuffer
(
"12345"
);
stringbuffer
.
append
(
"6789"
);
System
.
out
.
println
(
stringbuffer
);
// 123456789
// All StringBuffer methods modify the value of the object.
StringBuilder
sb
=
new
StringBuilder
(
"0123456789"
);
// StringBuilder delete(int startIndex, int endIndexPlusOne)
System
.
out
.
println
(
sb
.
delete
(
3
,
7
));
// 012789
StringBuilder
sb1
=
new
StringBuilder
(
"abcdefgh"
);
// StringBuilder insert(int indext, String whatToInsert)
System
.
out
.
println
(
sb1
.
insert
(
3
,
"ABCD"
));
// abcABCDdefgh
StringBuilder
sb2
=
new
StringBuilder
(
"abcdefgh"
);
// StringBuilder reverse()
System
.
out
.
println
(
sb2
.
reverse
());
// hgfedcba
// Similar functions exist in StringBuffer also
// All functions also return a reference to the object after modifying
// it.
// This allows a concept called method chaining.
StringBuilder
sb3
=
new
StringBuilder
(
"abcdefgh"
);
System
.
out
.
println
(
sb3
.
reverse
().
delete
(
5
,
6
).
insert
(
3
,
"---"
));
// hgf---edba
}
}
Back
|
FazBrowse Home
|
New Git URL