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 'Stringbuilder' - 6 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 | |||||||||||
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 | |||||||||||
| |||||||||||
Ans. private static boolean isPalindrome(String str) { if (str == null) return false; StringBuilder strBuilder = new StringBuilder(str); strBuilder.reverse(); return strBuilder.toString().equals(str); } | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   string   stringbuilder   stringbuilder   string class   code   palindrome Asked in 38 Companies Basic   frequent | |||||||||||
| |||||||||||
Ans. String str = new StringBuilder().append("Buggy").append("Bread").toString(); | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  java   builder pattern   design pattern   stringbuilder   string Asked in 3 Companies | |||||||||||
Try 1 Question(s) Test | |||||||||||
| |||||||||||
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 | |||||||||||
| |||||||||||
Ans. No but we have it in StringBuilder. | |||||||||||
Help us improve. Please let us know the company, where you were asked this question : | |||||||||||
Like Discuss Correct / Improve  String  StringBuilder  Reverse a string | |||||||||||
| |||||||||||
| |||||||||||
| |||||||||||