Search Interview Questions | More than 3000 questions in repository. There are more than 900 unanswered questions. Click here and help us by providing the answer. Have a video suggestion. Click Correct / Improve and please let us know. |
|
| |||||||||||
Core Java - Interview Questions and Answers for 'Stringbuffer' - 9 question(s) found - Order By Newest | |||||||||||
Very frequently asked in different variations. Frequently asked in Deloitte ( 2 feedback ) , HCL Tech ( 3 feedback ), TCS and Coginizant (CTS) | |||||||||||
| |||||||||||
Ans. If the Object value will not change, use String Class because a String object is immutable. If the Object value can change and will only be modified from a single thread, use StringBuilder because StringBuilder is unsynchronized(means faster). If the Object value may change, and can be modified by multiple threads, use a StringBuffer because StringBuffer is thread safe(synchronized). | |||||||||||
Sample Code for String Sample Code for StringBuffer Sample Code for StringBuilder | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   string class   string   stringbuilder   stringbuffer   String vs StringBuffer   String vs StringBuilder   String vs StringBuilder vs StringBuffer   StringBuffer vs stringBuilder Asked in 29 Companies basic   frequent | |||||||||||
Try 3 Question(s) Test | |||||||||||
| |||||||||||
Ans. java.lang.StringBuffer. | |||||||||||
Sample Code for StringBuffer | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   object class   stringbuffer expert   rare | |||||||||||
Very frequently asked. Usually asked in different variants like Diff between StringBuffer , String Builder ; Difference between StringBuilder and String class; Choice between these classes etc. | |||||||||||
| |||||||||||
Ans. A string buffer implements a mutable sequence of characters. A string buffer is like a String, but can be modified. At any point in time it contains some particular sequence of characters, but the length and content of the sequence can be changed through certain method calls. The String class represents character strings. All string literals in Java programs, such as "abc" are constant and implemented as instances of this class; their values cannot be changed after they are created. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   string   stringbuffer   frequently asked Asked in 18 Companies basic   frequent | |||||||||||
Try 1 Question(s) Test | |||||||||||
Very frequently asked. Usually difference between String,StringBuffer and StringBuilder is asked in different variations. | |||||||||||
| |||||||||||
Ans. StringBuffer is synchronized whereas StringBuilder is not. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   string   stringbuffer   string class   stringbuilder   synchronized   basic interview question   infosys technologies Asked in 17 Companies basic   frequent | |||||||||||
Try 1 Question(s) Test | |||||||||||
Very frequently asked in HCL Tech ( Based of 4 inputs ) | |||||||||||
| |||||||||||
Ans. Using String method - new StringBuffer(str).reverse().toString(); Iterative - public static String getReverseString(String str){ StringBuffer strBuffer = new StringBuffer(str.length); for(int counter=str.length -1 ; counter>=0;counter--){ strBuffer.append(str.charAt(counter)); } return strBuffer; } Recursive - public static String getReverseString(String str){ if(str.length <= 1){ return str; } return (getReverseString(str.subString(1)) + str.charAt(0); } | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   string   reverse   stringbuffer   string class   code Asked in 6 Companies   frequent | |||||||||||
| |||||||||||
Ans. BuggyBread | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   code   coding   stringbuffer   string   method calling   pass by reference | |||||||||||
| |||||||||||
Ans. Buggy | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   code   coding   stringbuffer   string   method calling   pass by reference | |||||||||||
| |||||||||||
Ans. Buggy | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   code   coding   stringbuffer   string   method calling   pass by reference | |||||||||||
| |||||||||||
Ans. No, they have been declared final and hence cannot be extended. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  StringBuffer  StringBuilder | |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||