Core java - Interview Questions and Answers for '360degree' - 2 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) Q1. Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
or
What is the difference between String , StringBuilder and StringBuffer ? Core Java
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) TestRelated Questions Difference between == and .equals() ? Why is String immutable in Java ? What are different ways to create String Object? Explain. Why Char array is preferred over String for storing password? What is a String Pool ? How does making string as immutable helps with securing information ? How does String Pool pose a security threat ? How is string object immutable if we can concat a string to it ? What is StringJoiner ? Which of the following is false about main method ?
a. It should be declared public and static
b. it should have only 1 argument of type String array
c. We can override main method
d. We can overload main method This question was recently asked at '360Degree'.This question is still unanswered. Can you please provide an answer. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Related Questions Difference between == and .equals() ? Why is String immutable in Java ? Explain the scenerios to choose between String , StringBuilder and StringBuffer ?
or
What is the difference between String , StringBuilder and StringBuffer ? What are the difference between composition and inheritance in Java? Explain OOPs
or
Explain OOPs Principles
or
Explain OOPs Concepts
or
Explain OOPs features
or
Tell me something about OOPs What is a Lambda Expression ? What's its use ? What are different ways to create String Object? Explain. Why Char array is preferred over String for storing password? Does garbage collection guarantee that a program will not run out of memory? What is the difference between final, finally and finalize() ?