Location via proxy:
[ UP ]
[Report a bug]
[Manage cookies]
No cookies
No scripts
No ads
No referrer
Show this form
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)
12 views
String Builder
Uploaded by
jenny
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save string builder For Later
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)
12 views
String Builder
Uploaded by
jenny
AI-enhanced title
Copyright
© © All Rights Reserved
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save string builder For Later
Carousel Previous
Carousel Next
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 feedback@javatpoint.com 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
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Mark Manson
4/5 (6125)
Principles: Life and Work
From Everand
Principles: Life and Work
Ray Dalio
4/5 (627)
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Brene Brown
4/5 (1148)
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
Chris Voss
4.5/5 (932)
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Jeannette Walls
4/5 (8214)
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Angela Duckworth
4/5 (631)
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
Jesmyn Ward
4/5 (1253)
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Stephen Chbosky
4/5 (8365)
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Phil Knight
4.5/5 (860)
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Carmen Maria Machado
4/5 (877)
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
Margot Lee Shetterly
4/5 (954)
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Ben Horowitz
4.5/5 (361)
Steve Jobs
From Everand
Steve Jobs
Walter Isaacson
4/5 (2922)
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
Ashlee Vance
4.5/5 (484)
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Siddhartha Mukherjee
4.5/5 (277)
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
Colm Toibin
3.5/5 (2061)
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Fredrik Backman
4.5/5 (4972)
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
Frank McCourt
4.5/5 (444)
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
Garth Stein
4/5 (4281)
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
Sarah M. Broom
4/5 (100)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
Meik Wiking
3.5/5 (447)
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Thomas L. Friedman
3.5/5 (2283)
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Roxane Gay
4/5 (1068)
Yes Please
From Everand
Yes Please
Amy Poehler
4/5 (1987)
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
Gilbert King
4.5/5 (278)
The Outsider: A Novel
From Everand
The Outsider: A Novel
Stephen King
4/5 (1993)
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
Ruth Ware
3.5/5 (2619)
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
Betty Smith
4.5/5 (1936)
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
Viet Thanh Nguyen
4.5/5 (125)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Dave Eggers
3.5/5 (692)
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Doris Kearns Goodwin
4.5/5 (1912)
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
Hilary Mantel
4/5 (4074)
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Naomi Klein
4/5 (75)
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Bob Woodward
3.5/5 (830)
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Jay Sekulow
3.5/5 (143)
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
Jennifer Egan
3.5/5 (901)
John Adams
From Everand
John Adams
David McCullough
4.5/5 (2530)
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
M L Stedman
4.5/5 (790)
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
George Packer
4/5 (45)
Little Women
From Everand
Little Women
Louisa May Alcott
4/5 (105)
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel
John le Carré
3.5/5 (109)
Related titles
Click to expand Related Titles
Carousel Previous
Carousel Next
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
From Everand
The Subtle Art of Not Giving a F*ck: A Counterintuitive Approach to Living a Good Life
Principles: Life and Work
From Everand
Principles: Life and Work
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
From Everand
The Gifts of Imperfection: Let Go of Who You Think You're Supposed to Be and Embrace Who You Are
Never Split the Difference: Negotiating As If Your Life Depended On It
From Everand
Never Split the Difference: Negotiating As If Your Life Depended On It
The Glass Castle: A Memoir
From Everand
The Glass Castle: A Memoir
Grit: The Power of Passion and Perseverance
From Everand
Grit: The Power of Passion and Perseverance
Sing, Unburied, Sing: A Novel
From Everand
Sing, Unburied, Sing: A Novel
The Perks of Being a Wallflower
From Everand
The Perks of Being a Wallflower
Shoe Dog: A Memoir by the Creator of Nike
From Everand
Shoe Dog: A Memoir by the Creator of Nike
Her Body and Other Parties: Stories
From Everand
Her Body and Other Parties: Stories
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
From Everand
Hidden Figures: The American Dream and the Untold Story of the Black Women Mathematicians Who Helped Win the Space Race
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
From Everand
The Hard Thing About Hard Things: Building a Business When There Are No Easy Answers
Steve Jobs
From Everand
Steve Jobs
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
From Everand
Elon Musk: Tesla, SpaceX, and the Quest for a Fantastic Future
The Emperor of All Maladies: A Biography of Cancer
From Everand
The Emperor of All Maladies: A Biography of Cancer
Brooklyn: A Novel
From Everand
Brooklyn: A Novel
A Man Called Ove: A Novel
From Everand
A Man Called Ove: A Novel
Angela's Ashes: A Memoir
From Everand
Angela's Ashes: A Memoir
The Art of Racing in the Rain: A Novel
From Everand
The Art of Racing in the Rain: A Novel
The Yellow House: A Memoir (2019 National Book Award Winner)
From Everand
The Yellow House: A Memoir (2019 National Book Award Winner)
The Little Book of Hygge: Danish Secrets to Happy Living
From Everand
The Little Book of Hygge: Danish Secrets to Happy Living
The World Is Flat 3.0: A Brief History of the Twenty-first Century
From Everand
The World Is Flat 3.0: A Brief History of the Twenty-first Century
Bad Feminist: Essays
From Everand
Bad Feminist: Essays
Yes Please
From Everand
Yes Please
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
From Everand
Devil in the Grove: Thurgood Marshall, the Groveland Boys, and the Dawn of a New America
The Outsider: A Novel
From Everand
The Outsider: A Novel
The Woman in Cabin 10
From Everand
The Woman in Cabin 10
A Tree Grows in Brooklyn
From Everand
A Tree Grows in Brooklyn
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
From Everand
The Sympathizer: A Novel (Pulitzer Prize for Fiction)
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
From Everand
A Heartbreaking Work Of Staggering Genius: A Memoir Based on a True Story
Team of Rivals: The Political Genius of Abraham Lincoln
From Everand
Team of Rivals: The Political Genius of Abraham Lincoln
Wolf Hall: A Novel
From Everand
Wolf Hall: A Novel
On Fire: The (Burning) Case for a Green New Deal
From Everand
On Fire: The (Burning) Case for a Green New Deal
Fear: Trump in the White House
From Everand
Fear: Trump in the White House
Rise of ISIS: A Threat We Can't Ignore
From Everand
Rise of ISIS: A Threat We Can't Ignore
Manhattan Beach: A Novel
From Everand
Manhattan Beach: A Novel
John Adams
From Everand
John Adams
The Light Between Oceans: A Novel
From Everand
The Light Between Oceans: A Novel
The Unwinding: An Inner History of the New America
From Everand
The Unwinding: An Inner History of the New America
Little Women
From Everand
Little Women
The Constant Gardener: A Novel
From Everand
The Constant Gardener: A Novel