File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes String  predefined method doubt??? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "String  predefined method doubt???" Watch "String  predefined method doubt???" New topic
Author

String predefined method doubt???

Vishal Hegde
Ranch Hand

Joined: Aug 01, 2009
Posts: 970

public class SB
{
public static void main(String args[])
{
StringBuffer s1=new StringBuffer();
StringBuffer s2=new StringBuffer();
s1.insert(0,"Hello from Java");
s2.insert(0, s2);
System.out.println(s1);
System.out.println(s2);
}

}

s2 is displaying nothing not even null as it is not even referecing to any object ,why is this happening???


http://www.lifesbizzare.blogspot.com || OCJP:81%
salvin francis
Ranch Hand

Joined: Jan 12, 2009
Posts: 915

Answer seems to be posted here:
http://www.coderanch.com/t/473341/Java-General/java/with-string-predefined-method

Please note OP in both the cases


My Website: [Salvin.in] Cool your mind:[Salvin.in/painting] My Sally:[Salvin.in/sally]
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19216

This problem is slightly different.

Vishal, what does s2 contain when you try to add it to itself? Also, please use code tags in the future.


SCJP 1.4 - SCJP 6 - SCWCD 5
How To Ask Questions How To Answer Questions
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 32611
    
    4
And also, your thread title doesn't quite tell us what the question is about. StringBuffer, not String, please.

By the way: StringBuilder is usually more efficient in that sort of circumstances.
 
I agree. Here's the link: http://zeroturnaround.com/jrebel
 
subject: String predefined method doubt???
 
Similar Threads
== and equals
StringBuffer var as an argument
Check the output!!
Inner Thread Classes
Can this be a case of deadlock ?And how to determine it output ?