File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String concat Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String concat" Watch "String concat" New topic
Author

String concat

Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
why concat is failing here?

[ June 12, 2002: Message edited by: Thiru Thangavelu ]

Thanks,<br />Thiru<br />[SCJP,SCWCD,SCBCD]
Brian Lugo
Ranch Hand

Joined: Nov 10, 2000
Posts: 165
Did you compile and run the program?
If yes, what do you think is the answer?
Brian
Thiru Thangavelu
Ranch Hand

Joined: Aug 29, 2001
Posts: 219
I think there is no method in String class as concat(StringBuffer). That's why the error is. Isn't?
geetha nagarajan
Ranch Hand

Joined: Jul 13, 2001
Posts: 94
String class has a concat method that takes only String as parameter.
So,only concat(String) will work.
It does not work with any other parameter.
Am i right?
Swati Gupta
Ranch Hand

Joined: May 28, 2002
Posts: 106
Even the line s.append("def"); will error out as String class does not have append.
Jie Zhou
Greenhorn

Joined: Jun 06, 2002
Posts: 8
Even the line s.append("def"); will error out as String class does not have append.

Actually s.append("def") will not cause error.
The overloaded method
StringBuffer append(String str)
appends the string "def" to this string buffer.
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Originally posted by Jie Zhou:

Actually s.append("def") will not cause error.
The overloaded method
StringBuffer append(String str)
appends the string "def" to this string buffer.

But s is a String and String does not have an append method, overloaded or not!


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Jie Zhou
Greenhorn

Joined: Jun 06, 2002
Posts: 8
Thanks, Thomas.
I thought s is a StringBuffer variable, but it is a Stirng.
Bonnie Beach-Morin
Greenhorn

Joined: Jun 13, 2002
Posts: 13
Even if the programmer used (and s.append("def) were removed), the code would not work as intended. The String class is immutable, so any call to the concat method returns a new String object and does not modify the original String object. The programmer would need to do something like


SJCP2
Gautam Sewani
Ranch Hand

Joined: Apr 19, 2002
Posts: 93
The last reply was the only correct reply!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String concat