Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
16 views
12 pages
String Builder
Uploaded by
jenny
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download
Save
Save string builder For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
16 views
12 pages
String Builder
Uploaded by
jenny
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Carousel Previous
Carousel Next
Download
Save
Save string builder For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 12
Search
Fullscreen
814723, 1148 AM Java StingBullderclass-javatpoint hitps ww javatpoint com/StingBuilder-cass wn814723, 1148 AM Java StingBuiler clas: javatpoint Java StringBuilder Class Java StringBuilder class is used to create mutable (modifiable) String. The Java StringBuilder class is same as StringBuffer class except that it is non-synchronized. It is available since JDK 1.5. Important Constructors of StringBuilder class Constructor Description StringBuilder It creates an empty String Builder with the initial capacity of 16. StringBuilder(String str) It creates a String Builder with the specified string, StringBuilder(int length) | It creates an empty String Builder with the specified capacity as length. Important methods of StringBuilder class Method Description public StringBuilder It is used to append the specified string with this string. The append(String s) append) method is overloaded like append{char), append(boolean), append(int), append(float), append(double) ete. public StringBuilder insert(int It is used to insert the specified string with this string at the offset, String s) specified position. The insert) method is overloaded like insert(int, char), insert(int, boolean), insert(int, int), insert(int, float), insert{int, double) etc. public StringBuilder It is used to replace the string from specified startindex and replace(int startindex, int _ endlndex. endindex, String str) ntps:iwwwjavatpoin comStinguller-lass ane814723, 1148 AM public StringBuilder delete(int startindex, int endindex) public StringBuilder reverse) public int capacity() public void ensureCapacity(int minimumCapacity) public char charAt(int index) public int length public String substringiint beginindex) public String substring(int beginindex, int endindex) Java StingBullderclass-javatpoint It is used to delete the string from specified startIndex and endindex. Itis used to reverse the string. It is used to return the current capa It is used to ensure the capacity at least equal to the given minimum It is used to return the character at the specified position. It is used to return the length of the string ie. total number of characters. Itis used to return the substring from the specified beginIndex. It is used to return the substring from the specified beginindex and endindex. Java StringBuilder Examples Let's see the examples of different methods of StringBuilder class. 1) StringBuilder append() method The StringBuilder append() method concatenates the given argument with this String. StringBuilderExample java ntps:wwwjavatpoin.comStingBul ane814723, 1148 AM Java StingBuiler clas: javatpoint class StringBuilderExample{ public static void main(String args()){ StringBuilder sb=new StringBuilder("Hello "); sb.append("Java");//now original string is changed System.out printin(sb);//prints Hello Java ) } Output: Hello Java 2) StringBuilder insert() method The StringBuilder insert) method inserts the given string with this string at the given position StringBuilderExample2,java class StringBuilderExample2( public static void main(String args()){ StringBuilder sb=new StringBuilder("Hello " sb.insert(1,"Java");//now original string is changed System.out printin(sb);//prints HJavaello } } Output: HJavaello ntps:iwwwjavatpoin comStinguller-lass ana,814723, 1148 AM Java StingBuiler clas: javatpoint 3) StringBuilder replace() method The StringBuilder replace method replaces the given string from the specified beginindex and endindex. StringBuilderExample3 java class StringBuilderExample3( public static void main(String args(){ StringBuilder sb=new StringBuilder("Hell sb.replace(1,3,"Java"); System.out printin(sb);//prints HJavalo ) } Output: HJavalo 4) StringBuilder delete() method The delete() method of StringBuilder class deletes the string from the specified beginindex to endindex. StringBuilderExample4 java tps: javatpoin com/Stinguller-lass sz623, 1148 0M Java StringBuilder las-jvatpoit class StringBuilderExampled{ public static void main(String args()){ StringBuilder sb=new StringBuilder("Hello’); sbdelete(1,3); System.out printin(sb);//prints Hio } ) Output: Hlo 5) StringBuilder reverse() method The reverse() method of StringBuilder class reverses the current string. StringBuilderExample5 java class StringBuilderExample5{ public static void main(String args()){ StringBuilder sb=new StringBuilder("Hello’); sb.reverse(; System.out printin(sb);//prints olleH ) ) Output: olleH ntps:iwwwjavatpoin comStinguller-lass en2814723, 1148 AM Java StingBuiler clas: javatpoint 6) StringBuilder capacity() method The capacity() method of StringBuilder class returns the current capacity of the Builder. The default capacity of the Builder is 16. If the number of character increases from its current capacity, it increases the capacity by (oldcapacity*2)+2. For example if your current capacity is 16, it will be (16*2)+2=34, StringBuilderExample6.java class StringBuilderExample6{ public static void main(String args()){ StringBuilder sb=new StringBuilder); System.out printin(sb.capacity();//default 16 sb.append("Hello"); System.out.printin(sb.capacity0);//now 16 sb.append("Java is my favourite language"); System.out printin(sb.capacity())i//now (16*2)+2=34 i.e (oldcapacity*2)+2 } } Output: 16 16 34 7) StringBuilder ensureCapacity() method The ensureCapacity) method of StringBuilder class ensures that the given capacity is the minimum to the current capacity. If it is greater than the current capacity, it increases the capacity by (oldcapacity*2)+2. For example if your current capacity is 16, it will be (16*2)+2=34. ntps:iwwwjavatpoin comStinguller-lass m2814723, 1148 AM Java StingBullderclass-javatpoint StringBuilderExample7.java class StringBuilderExample7{ public static void main(String args{)){ StringBuilder sb=new StringBuilder); System.out.printin(sb.capacity();//default 16 sb.append("Hello"); System.out printin(sb.capacity());//now 16 sb.append("Java is my favourite language"); System.out printin(sb.capacity();//now (162)+2=34 ie (oldcapacity*2)+2 sb.ensureCapacity(10);//now no change System.out printin(sb.capacity());//now 34 sb.ensureCapacity(50);//now (34*2)+2 System.out printin(sb.capacity());//now 70 } } Output: 16 16 34 34 78 Youtube For Videos Join Our Youtube Channel: Join Now hitps ww javatpoint com/StingBuilder-cass814723, 1148 AM Feedback © Send your Feedback to
[email protected]
Help Others, Please Share Learn Latest Tutorials #Splunk tutorial Splunk Tumblr tutorial Tumble AR Programming tutorial R Programming |e Python Pillow tutorial Python Pillow Preparation (Aptitude nips: javatpoin.comiStingBulk WeiSPSS tutorial spss React tutorial ReactlS We:RXIS tutorial Rus (22 Python Turtle tutorial Python Turtle le Swagger tutorial Swagger PRegex tutorial Regex ii React Native tutorial React Native wKeras tutorial Keras Java StingBullderclass-javatpoint |AT-SQL tutorial ‘Transact-SQL (2) Reinforcement learning tutorial Reinforcement Learning, (3 Python Design Patterns, Python Design Patterns onz814723, 1148 AM Aptitude B Company Interview Questions ‘Company Questions Logical Reasoning Reasoning Trending Technologies lf Artificial Intelligence Antificial Intelligence PHadoop tutorial Hadoop \#2 Blockchain Tutorial Blockchain AWS Tutorial AWS: i Reacts Tutorial ReactlS WGit Tutorial Git ntps:iwwwjavatpoin comStinguller-lass Java StingBullderclass-javatpoint pNerbal Ability Verbal Ability (A Selenium tutorial Selenium (e2 Data Science Tutorial Data Science (2 Machine Leaming Tutorial Machine Leaning. (#2 Interview Questions Interview Questions li Cloud ‘Computing Cloud Computing, (2 Angular 7 Tutorial Angular 7 ii DevOps. ‘Tutorial DevOps s0112814/29, 1148.AM B.Tech / MCA DBMS tutorial DBMS Computer Network tutorial Computer Network (FEthical Hacking Ethical Hacking igi Cyber Security tutorial Cyber Security Pava tutorial Java (Data Structures tutorial Data Structures (2 Compiler Design tutorial Compiler Design Computer Graphics Tutorial Computer Graphics (A Automata Tutorial ‘Automata Net Framework tutorial Net nips: javatpoin.com/Stingullder-lass Java StingBullderclass-javatpoint DAA tutorial DAA Computer Organization and Architecture Computer Organization B. Software Engineering Software Engincering i) C Language tutorial C Programming # Python tutorial Python A) Operating System Operating System lei Discrete Mathemati Tutorial Diserete ‘Mathematics Fbtml tutorial Web Technology AC+ tutorial 2 Listot Programs Programs wie814723, 1148 AM Java StingBullderclass-javatpoint ‘2 Control 2) Data Mining 2 Data Systems tutorial Tutorial Warehouse Control System Data Mining Tutorial Data Warehouse ntps:iwwwjavatpoin comStinguller-lass rane
You might also like
Java Strings
PDF
No ratings yet
Java Strings
51 pages
Programming 1A: (PROG5121)
PDF
No ratings yet
Programming 1A: (PROG5121)
12 pages
Lecture 12 String, StringBuffer and StringTokenizer Class
PDF
No ratings yet
Lecture 12 String, StringBuffer and StringTokenizer Class
33 pages
StringBuffer Class
PDF
No ratings yet
StringBuffer Class
26 pages
m4 Java
PDF
No ratings yet
m4 Java
80 pages
Module1 String handling-AJ-BIS402
PDF
No ratings yet
Module1 String handling-AJ-BIS402
63 pages
Strsearch, Modify, Buffer
PDF
No ratings yet
Strsearch, Modify, Buffer
28 pages
Fall Semester 2024-25 - STS3004 - TH - AP2024252001206 - 2024-09-13 - Reference-Material-I
PDF
No ratings yet
Fall Semester 2024-25 - STS3004 - TH - AP2024252001206 - 2024-09-13 - Reference-Material-I
51 pages
CH 7 (Strings)
PDF
No ratings yet
CH 7 (Strings)
39 pages
Lec 8
PDF
No ratings yet
Lec 8
32 pages
String and I/O
PDF
No ratings yet
String and I/O
91 pages
OOPs - Lecture 12 - String Buffer, String Builder
PDF
No ratings yet
OOPs - Lecture 12 - String Buffer, String Builder
14 pages
Arrays, Strings
PDF
No ratings yet
Arrays, Strings
21 pages
Fall Semester 2024-25 - STS3004 - TH - AP2024252001206 - 2024-09-18 - Reference-Material-I
PDF
No ratings yet
Fall Semester 2024-25 - STS3004 - TH - AP2024252001206 - 2024-09-18 - Reference-Material-I
34 pages
String Buffer
PDF
No ratings yet
String Buffer
26 pages
String
PDF
No ratings yet
String
25 pages
Java Api
PDF
No ratings yet
Java Api
45 pages
Strings
PDF
No ratings yet
Strings
9 pages
String Handling Complete Notes
PDF
No ratings yet
String Handling Complete Notes
18 pages
Java 4th Unit
PDF
No ratings yet
Java 4th Unit
46 pages
WINSEM2024-25 BCSE103E ELA VL2024250505252 2025-02-03 Reference-Material-II
PDF
No ratings yet
WINSEM2024-25 BCSE103E ELA VL2024250505252 2025-02-03 Reference-Material-II
20 pages
String 1 Notes
PDF
No ratings yet
String 1 Notes
22 pages
Strings Class
PDF
No ratings yet
Strings Class
27 pages
String
PDF
No ratings yet
String
33 pages
Strings
PDF
No ratings yet
Strings
15 pages
3 4 String
PDF
No ratings yet
3 4 String
67 pages
X (Lec-25 or 30) Java SE (String Handling)
PDF
No ratings yet
X (Lec-25 or 30) Java SE (String Handling)
17 pages
String Handling
PDF
No ratings yet
String Handling
33 pages
Strings in Java
PDF
No ratings yet
Strings in Java
12 pages
Java Unit2
PDF
No ratings yet
Java Unit2
23 pages
Strings
PDF
No ratings yet
Strings
22 pages
StringBuilder Class
PDF
No ratings yet
StringBuilder Class
13 pages
Skip To Contentb
PDF
No ratings yet
Skip To Contentb
12 pages
23-Java String
PDF
No ratings yet
23-Java String
7 pages
Strings
PDF
No ratings yet
Strings
9 pages
Dokumen - Tips 11 String and String Builder Java
PDF
No ratings yet
Dokumen - Tips 11 String and String Builder Java
33 pages
Characters Strings and StringBuilder
PDF
No ratings yet
Characters Strings and StringBuilder
21 pages
Skip To Contenta
PDF
No ratings yet
Skip To Contenta
10 pages
Java Imp Topics
PDF
No ratings yet
Java Imp Topics
5 pages
Java StringBuilder Methods Descriptions Examples
PDF
No ratings yet
Java StringBuilder Methods Descriptions Examples
2 pages
String Handling (StringBuilder Class)
PDF
No ratings yet
String Handling (StringBuilder Class)
27 pages
Java Programming: Arrays & String Manipulation
PDF
No ratings yet
Java Programming: Arrays & String Manipulation
23 pages
1) Stringbuffer Append Method: Class Public Static Void New
PDF
No ratings yet
1) Stringbuffer Append Method: Class Public Static Void New
6 pages
String Buffer
PDF
No ratings yet
String Buffer
22 pages
Java StringBuffer Class
PDF
No ratings yet
Java StringBuffer Class
9 pages
Char&String in Java
PDF
No ratings yet
Char&String in Java
7 pages
StringBuffer Class
PDF
No ratings yet
StringBuffer Class
6 pages
Aman Kant Sudhanshu - Analysis On StringBuffer and StringBuilder Classes
PDF
No ratings yet
Aman Kant Sudhanshu - Analysis On StringBuffer and StringBuilder Classes
15 pages
Lab 3
PDF
No ratings yet
Lab 3
8 pages
String Manipulations: Core Java
PDF
No ratings yet
String Manipulations: Core Java
13 pages
String Builder and String Buffer in Java
PDF
No ratings yet
String Builder and String Buffer in Java
4 pages
Pract 7
PDF
No ratings yet
Pract 7
4 pages
8 (1) Strings
PDF
No ratings yet
8 (1) Strings
19 pages
6.3 Java StringBuilder Class A
PDF
No ratings yet
6.3 Java StringBuilder Class A
3 pages
Strings: Mutable Object - You Can Change The States and Fields After The Object Is
PDF
No ratings yet
Strings: Mutable Object - You Can Change The States and Fields After The Object Is
10 pages
Module6-String Builder Class
PDF
No ratings yet
Module6-String Builder Class
4 pages
Chapter 9: String, Stringbuffer, Stringbuilder (3 HRS) Chapter Objectives
PDF
No ratings yet
Chapter 9: String, Stringbuffer, Stringbuilder (3 HRS) Chapter Objectives
8 pages
String Buffer
PDF
No ratings yet
String Buffer
5 pages