amu61
amu61

Reputation: 351

StringBuffer , StringBuidler

StringBuidler sb="ram" StringBuffer sf = "ram"

Both throws comile time error . Please explain Why??????

Upvotes: 0

Views: 131

Answers (3)

Marcus
Marcus

Reputation: 1876

Because StringBuilder and StringBuffer isn't strings. You need to write

sb = new StringBuilder("ram")

Upvotes: 1

Ulrich Schwarz
Ulrich Schwarz

Reputation: 7727

There's no promotion from String to StringBuilder/Buffer. Try

StringBuilder = new StringBuilder("ram")

Upvotes: 4

JohnFx
JohnFx

Reputation: 34909

Perhaps because it is "StringBuilder" not "StringBuidler"?
Or maybe because you need a semi-colon between the two lines?
Or that "ram" is a string and not a StringBuilder or StringBuffer?

Upvotes: 0

Related Questions