I am working with StringBuffer
. Using NetBeans 8.1
IDE.
Code I wrote:
package stringbuffer;
import java.lang.*;
public class StringBuffer {
public static void main(String[] args) {
StringBuffer sb=new StringBuffer("hello");
}
}
But this is showing error like this:
What's my problem?
You've named your class StringBuffer
. So it shadows java.lang.StringBuffer
(and you never have to import java.lang.*
). Rename your class, or use the fully qualified StringBuffer
name.
public class StringBuffer {
public static void main(String[] args) {
java.lang.StringBuffer sb=new java.lang.StringBuffer("hello");
}
}
or
public class MyStringBuffer {
public static void main(String[] args) {
StringBuffer sb=new StringBuffer("hello");
}
}