StringBuilder Methods are not working in classes in packages made by me but working fine in default packages.
StringBuilder are not workin in my eclipse
That should not happen, can you tell me what compilation error the ide is showing? Are you sure you have initialized it correctly?
StringBuilder s = new StringBuilder();
Whichever method of string builder I am using it says its not defined. Its happening not in those classes which are under packages not in default packages.
For eg :- I use sb.length(). for this method error is lenth() is undefined for type StringBuilder.
Can you please share your complete code for which you are trying to use stringbuilder? There is probably some minor error in syntax
package section5;
public class StringBuilderDemo {
public static void main(String[] args) {
StringBuilder sb = new StringBuilder();
int a = sb.length();
System.out.println(a);
}
}
Your code seems correct and is working for me in my eclipse ide. I have transferred your doubt to a mentor, they will help you with it.
I added (import java.lang.StringBuilder;) to the code, now its working fine.
Okay, that’s great. Though it usually works without importing as well.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.