The Artima Developer Community
Sponsored Link

Java Answers Forum
what is the difference string and stringbuffer?

1 reply on 1 page. Most recent reply: Oct 16, 2002 1:49 AM by Ramzi Ben Yahia

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 1 reply on 1 page
senthil

Posts: 23
Nickname: rickk84
Registered: Aug, 2002

what is the difference string and stringbuffer? Posted: Oct 15, 2002 4:43 AM
Reply to this message Reply
Advertisement
what is the difference string and stringbuffer?


Ramzi Ben Yahia

Posts: 23
Nickname: miccheck
Registered: Jul, 2002

Re: what is the difference string and stringbuffer? Posted: Oct 16, 2002 1:49 AM
Reply to this message Reply
String instances are immuatable , StringBuffer aren't
in fact when you try something like this

String s = new String();
s = s + "chain";

is as if you've done instead
s = new String(s + "chain");

when you use StringBuffer like this:

StringBuffer buff = new StringBuffer();
buff.append(s).append("chain");
buff will always keep the same reference.

that's why it's recommended to use StringBuffer instead of String when you manipulate String.
for it saves memory and avoid creation of many String instances.

StringTokenizer is also recommended to replace
methods in String class as substring..

Flat View: This topic has 1 reply on 1 page
Topic: Testing tool for web application Previous Topic   Next Topic Topic: i need to configure the iplanet web server 6

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use