Home Answers Viewqa Java-Beginners 'String' vs 'StringBuffer'

 
 


somasekhar
'String' vs 'StringBuffer'
2 Answer(s)      5 years and 2 months ago
Posted in : Java Beginners

What should i use String or StringBuffer?

View Answers

March 20, 2008 at 8:23 PM


Hi,
First you need to rectify the question. Because StringBuffers append the data, and Strings concatenate the data. Since Strings are immutable a new object is created for each concat operation. So it is better to use StringBuffer when you are append different data to the same StringBuffer object.

July 11, 2011 at 6:05 PM


The main benefit of String is immutability which differentiate it from Stringbuffer but in case of string manipulation this advantage becomes biggest disadvantage and creates lots of garbage also using "+" operator for String concatenation is very slow as compared to StringBuffer.append()method which cost you some performance.









Related Pages:
'String' vs 'StringBuffer' - Java Beginners
'String' vs 'StringBuffer'  What should i use String or StringBuffer?  Hi, First you need to rectify the question. Because StringBuffers... StringBuffer when you are append different data to the same StringBuffer object
StringBuffer
StringBuffer  What's the difference between these two formats? String string=args[0]; String reverse = new StringBuffer(string).reverse().toString(); String string=args[0]; StringBuffer rev = string.reverse(); String
String and StringBuffer - Java Beginners
; Hi vijay Java provides the StringBuffer and String classes.... Simply stated, objects of type String are read only and immutable. The StringBuffer... than String when performing simple concatenations. StringBuffer is mainly
StringBuffer and StringBuilder
StringBuffer and StringBuilder  package org.day.strings; import java.io.BufferedReader; public class Test { public static void main(String[] args) { StringBuffer sb1 = new StringBuffer(); sb1.append
String and stringbuffer object - Java Beginners
String and stringbuffer object  Hi, What is the basic difference between string and stringbuffer object? Thanks   Hi Friend... be modified. 2)StringBuffer is faster than String. 3)String Objects
StringBuffer and StringBuilder
a string buffer. Extracting from StringBuffer c = ... compared to String Because a StringBuffer object is mutable (it can be changed... String dupl(String s, int times) { StringBuffer result = new StringBuffer(s
stringbuffer - Java Beginners
DeleteString { public static void main(String args[]) { StringBuffer sb = new StringBuffer("Rose India Tech"); //Removes the characters at index 10 to 15 in the StringBuffer. sb.delete(10, 15); System.out.println("After delete
StringBuffer - Java Beginners
question regarding StringBuilder And StringBuffer. But,while using more than one...-threaded applications(i.e. StringBuffer)? Please give example(code) and explain   Hi public class MultiTread implements Runnable{ private String name
Differences between the String, StringBuilder, and StringBuffer classes
Differences between the String, StringBuilder, and StringBuffer classes StringBuffer versus String Java provides the StringBuffer and String classes... on the StringBuffer object, it must be converted back into a String
Java - StringBuffer class in Java
; StringBuffer is mainly used for the dynamic string concatenation which... Java - StringBuffer class in Java       In this example you will learn about StringBuffer
Creation of StringBuffer
Constructor with 16 characters set StringBuffer(String s) //String to String... the String buffer and capacity of StringBuffer. Therefore we get the following... Creation of StringBuffer      
StringBuilder v/s StringBuffer - Java Beginners
Character!"); String st = buff.readLine(); StringBuffer sb =new.... String str; int a = 42; StringBuffer buffer= new StringBuffer(40); str...... Threads run simultaneously. But in case of BOTH StringBuilder & StringBuffer
StringBuilder v/s StringBuffer - Java Beginners
between StringBuilder & StringBuffer classes. I know that StringBuffer... often causes many temporary string objects to be created, which can be quite inefficient. StringBuilder (or StringBuffer) are better choices in these cases
doGet() Vs doPost()
doGet() Vs doPost()  plz explain the differences between both...() method doesn't have this limitation. A request string for doGet() looks like... in a request. All parameters are stored in a request itself, not in a request string
PHP Comma vs Period - PHP
PHP Comma vs Period  Explain PHP Comma vs Period. And also how can one show a comma within a comma separated file.   Hi Friend, Please...-String-to-Array.html Thanks
StringBuffer related.
StringBuffer related.  how to make StringBuffer as immutable
Java vs Oracle Connectivity - JDBC
Java vs Oracle Connectivity  Write a java program to establish... { public static void main (String[] args) { try{ DriverManager.registerDriver(new... student"); String str = ""; while (rs.next()) { System.out.println(rset.getInt
Encapsulation VS Abstraction - Java Beginners
Encapsulation VS Abstraction  Real Time sample code for Encapsulation and Abstraction. where to use abstract and where to use specifies like public... static void main(String args [ ]) { Box b1=new Box(3,4,5); b1.displayvolume
Java vs. C
, String and StringBuffer, that are used to store strings of characters. C uses... Java: Java vs. C Is Java easier or harder than C? Java is harder because... of characters in Java if you need to, but it is usually easier to use String
String Buffer insert and append example
String Buffer insert and append example   ... with StringBuffer and append data to it. The StringBuffer is a class that implements multiple sequence of characters. The following program construct a string buffer
StringBuffer - Java Beginners
StringBuffer  Can any one help with this naughty problem? Replacing a character with two characters in a StringBuffer. Replacing a character...;} converting the StringBuffer using charArray[] also worked well, but not where
(ii) String and String Buffer Class
between String and StringBuffer 1) String object is immutable whereas StringBuffer objects are mutable. 2) String objects are constants...String and String Buffer Class  difference between String and String
String reverse in java
String Buffer "); String reverses = new StringBuffer(word1).reverse...String reverse in java In this section we are going to discuss about how to reverse a sting in java. There are many ways to reverse a string in java 
Java string buffer
Java string buffer  what is stringBuffer and StringBuilder
Example: String reverse
Example: String reverse The following program reverses a string in a very... (or the equivalent StringBuffer), you can do this more efficiently. But the purpose of this is to see how looping over a string works. Nested loops
STRING FUNCTIONS
String removeCharAt(String s, int pos) { StringBuffer buf = new StringBuffer...); String str1=removeCharAt(st,index1); String str=new StringBuffer(str1...STRING FUNCTIONS  HERE IS THE QUESTION THAT I HAVE IN MY INFORMATICS
String doubts - Java Interview Questions
String doubts  difference between String and StringBuffer
reverse string
=input.nextLine(); String reverse = new StringBuffer(str).reverse().toString...reverse string  how to reverse a string without changing its place...{ public static void main(String[]args){ Scanner input=new Scanner
Java string buffer
Java string buffer  What is the basic difference between string and stringbuffer object
string reverse order
){ String s= " kalins naik" ; StringBuffer buffer = new StringBuffer(s...string reverse order  Hi I have string s= " kalins naik" then how can i print string s=" naik kalins" Thanks kalins naik   import
websphere vs weblogic
websphere vs weblogic  websphere vs weblogic Why you are using websphere instead of weblogic
encapsulation vs abstraction
encapsulation vs abstraction  what is the difference between encapsulation and abstraction
oracle vs sql
oracle vs sql  what is the difference between oracle and sql
explain the difference between string builder and string buffer classes
explain the difference between string builder and string buffer classes  Hi, Here is my code public static void main(String[] args) { String s1 = "abc"; StringBuffer s2 = new StringBuffer(s1); StringBuffer s3 = s2
Interface vs abstract class
Interface vs abstract class  Hai, Is there any possible to defining abstract methods in Interface
JETM vs Jprofiler
JETM vs Jprofiler  Can anyone explain the difference between Java Execution Time Measurement(JETM) and Jprofiler
compiler vs interpreter
compiler vs interpreter  "compiled program executes faster especially if the program contains loop" Why
String Mirror in Java
String Mirror in Java  how to get a mirror image of(string) a given string in java   Hello Friend, Try this: import java.util.*; class StringMirror{ public static void main(String []args){ String str="hello
ejb vs hibernate - EJB
ejb vs hibernate  1>>> If we have ejb entity bean why we need hibernate? 2>>> Is hibernate distributed
Getting the string in reverse
(); StringBuffer buffer=new StringBuffer(); String str[]=st.split... String: "); String st=input.nextLine(); StringBuffer buffer=new StringBuffer(); String str[]=st.split(" "); for(int i=str.length-1
string - Java Beginners
(); StringBuffer sb= new StringBuffer(words); String reversedWords=sb.reverse... java.util.*; class CountPalindromes{ public static void main(String[] args){ int... sentence: "); String str=input.nextLine(); StringTokenizer stk=new
ejbSelect() vs ejbHome() - EJB
ejbSelect vs ejbHome  Hi, 1) What are the differences between ejbSelect() and ejbHome...() business methods in CMP bean? 2) In Ed Romans Mastering EJB 3rd edition, it is mentioned that ejb finder methods
Derby vs MySQL - SQL
Derby vs MySQL  Hi, I want to know what are the advantages using Derby Database over MySQL.  http://www.roseindia.net/eclipse/plugins/database/index.shtml
inheritence Vs inheritence
inheritence Vs inheritence  what are difference b/w c++ inheritence and java inheritence   Hi Friend, C++ supports Multiple Inheritance while Java does not. Thanks
java vs vb
java vs vb  history of java and advanced products as well as vb? compared with java and vb? finalize list out the table of java and vb products? viewers i want more soon
Summary - String
and interfaces for String class. StringBuilder and StringBuffer are much more...Java: Summary - String String Concatenation Following table shows how to perform the string concatination operations. "abc" + "def
portability vs platform independent
portability vs platform independent  sir, pls tell me 1.the differences between platform independent and portability related to java technology 2.how java provides security 3.how can i prove servlet is a single instance
java vs .net - Java Beginners
java vs .net  which language is powerful now java or .net
String in Java - Java Beginners
in advance   Hello Antony Insted Using String Array Use StringBuffer...String in Java  hiiiii i initialise a String array,str[] with a size...; Hi friend, This is simple code of String Array. class StringArray
Java String operations
StringBuffer(); String str; while((str=br.readLine())!=null...Java String operations  hi, please suggest me how to write the java...*; class ReadFileIgnoringSomeLines { public static void main(String[] args

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.