How to create an array by calling args contructor?
StringBuilder[] sb=new StringBuilder[100];
But if I check sb[0] it is null. I want that sb[0] to sb[99] initialized with "".
Following results in an error:
StringBuilder[] sb=new StringBuilder[100]("");
EDIT: Or I have to do this:
for(StringBuilder it:sb)
{
it=new StringBuilder("");
}
All your code will do is initialise an array ready for 100 StringBuilders. It won't actually populate it.
You could do this:
StringBuilder[] sb=new StringBuilder[100];
for (int i = 0; i < sb.length; i++) {
sb[i] = new StringBuilder("");
}
That should do it for you.
It will always be null
. You have to initialize it manually if you want ""
in there.
Instead you could access the array by a method which returns ""
if the value is null
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With