GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Java-Programs/String/StringBufferBuilderExamples.java at master · divScorp/Java-Programs

Expand file tree

/

StringBufferBuilderExamples.java

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
33 lines (26 loc) · 1.16 KB
/

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
}
}
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.