Domanda di colloquio di Fidelity Investments

Difference between String and Stringbuilder in Java. (Phone screen question)

Risposta di colloquio

Anonimo

25 nov 2014

String objects are immutable. Consider an example, String s= "test"; s.o.p(s+"interview"); The above code creates a second object for concatenation internally which is a performance issue. Consider a string buffer, StringBuilder sb = new StringBuilder("test"); sb.append("interview"); Both of them perform the concatenation operation but using String class which is immutable gives rise to performance issues where as StringBuilder class is mutable and updates the existing object!

Glassdoor | Glassdoor