aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes String buffer problems Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "String buffer problems" Watch "String buffer problems" New topic
Author

String buffer problems

Kamil Dada
Ranch Hand

Joined: Aug 07, 2001
Posts: 43
1 class Q2
2 {
3 public static void main(String arg[])
4 {
5 StringBuffer s[]={"A","B"};
6 System.out.println(s[0]+","+s[1]);
7 }
8 }
The answer was: Comile time error:Casting needed to convert String to StringBuffer in line no. 5.
Firstly what is StringBuffer and why is it giving me this error?
Thank You,
Kamil
swati bannore
Ranch Hand

Joined: Oct 18, 2000
Posts: 201
Hi,
StringBuffer is a java API class.You can create mutable strings using this class.StringBuffer objects should be created using new operator.
StringBuffer buf = new StringBuffer("Javaranch");
In your code, you r trying to create in a wrong way.
Go thru the Java API specification for more details.

Swati Kale
SCJP
SCWCD
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Swati is right!
When using stringBuffer in an array try this code
<CODE>


class Q2 {
public static void main(String arg[]) {
StringBuffer s[]={new StringBuffer( "A" ), new StringBuffer( "B" ) };
System.out.println( s[0].toString() + "," + s[1].toString() );
}
}

</CODE>
Hope this helps!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: String buffer problems