String and StringBuffer

How we show with example difference between String and String Buffer
[75 byte] By [S_Gaurava] at [2007-11-27 5:52:07]
# 1

Use Google stupid.

[url=http://forum.java.sun.com/thread.jspa?threadID=400783&messageID=1747511]String vs String Buffer[/url]

[url=http://forum.java.sun.com/thread.jspa?threadID=268514&messageID=1024221]Clarification of String Vs StringBuffer[/url]

[url=http://forum.java.sun.com/thread.jspa?threadID=675860]what is difference between string and stringbuffer?[/url]

cotton.ma at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 2
- look at API docs for both- find method in one that's not in the other. try StringBuffer.append- write codez
OnBringera at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 3
strings can;t be modified whereas stringbuffer can be.
Yogesh.Nandwanaa at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 4

> strings can;t be modified whereas stringbuffer can be.

import java.lang.reflect.*;

public class ImmutableStringDemo {

public static void main(String[] args) throws Exception {

String string = "foo";

System.out.println(string); // foo

new StringChanger().change(string);

System.out.println(string); // bar

}

}

class StringChanger {

public void change(String s) throws IllegalAccessException {

Field[] fields = s.getClass().getDeclaredFields();

for (Field f : fields) {

f.setAccessible(true);

if (f.getType() == char[].class) {

f.set(s, "bar".toCharArray());

}

}

}

}

QED.

~

yawmarka at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 5
@yawmark: You are so evil!
thomas.behra at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 6
> public class ImmutableStringDemo {In other news, it has come to light that I can get by the Schlage industrial strength deadbolt in your front door with an Abrams tank... :)
kevjavaa at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 7
yawmark is gr8!!!
Yogesh.Nandwanaa at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...
# 8

> In other news, it has come to light that I can get by

> the Schlage industrial strength deadbolt in your

> front door with an Abrams tank... :)

Indeed. It would be silly of me to say you couldn't break into my house, despite the fact that I had taken reasonable precautions to prevent entry.

You can't turn my house into a fire-breathing pickle. But you can get in the front door if you try hard enough. :o)

~

yawmarka at 2007-7-12 15:42:21 > top of Java-index,Java Essentials,Java Programming...