Here’s how you use StringBuilder

Now get out of that bad habit of using String objects to perform operations on strings. With StringBuilder(introduced in J2Se 5.0), you can perform those very append and other such operations more efficiently.

Scene 1: typical coder…. using the same old String object to perform append operations.

String s = “Hello”;

s = s + ” World”;

system.out.println(s);

I agree it’ll give you “Hello World”, but fella…. let’s be different from the rest and think about making the code more efficient.

Enter Scene 2.

StringBuilder sb = new StringBuilder(“Hello”);

sb.append(” World”);

system.out.println(sb);

well… thats it!! You’ll get your “Hello World” but in a more efficient way :)

21 comments

  1. Thanks,Its very much informative and easy to get.

  2. good answer..thanks

  3. Good explanation .. nice

  4. Easy example to differentiate string and string builder.. thanks..

  5. good way to explain. thanks alot and keep it up.

  6. Nicely and well explained about String, StringBuffer and StringBuilder. thanks

  7. Glad you found it useful :)

  8. nice explanation with example.

  9. good exlanation, thanks

  10. Its really useful and definitely a very practical explanation

  11. Deepak mishra

    it explain very well,it’s really easy to understand…

  12. Very nice explaination of strings…i learnt it listening to music :-)

  13. Good way of explaining it,thanks :-)

  14. Nice.. it was informative, easy and useful. Thx.

  15. Very good explanation, I am impressed.

  16. Thank you..very useful

  17. thanks for Explaining in a easy way

  18. very simple and nice explanation thanks for that

  19. Very good explanation.Thanks.

  20. Easy to understanding,Thanks….

  21. Thanks a lot. Was very useful

Leave a comment