Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insufficient String Buffer Declaration

Tags:

java

I use tool to check coding style And I got many advise :

StringBuffer constructor is initialized with size 16, but has at least 35 characters appended.

Here is some of my code:

final StringBuffer Contents = new StringBuffer();

WHy whould this happen?
How did it count 35 characters?
How can I edit the size of StringBuffer ?
Or What method should I use to solve this problem??

like image 692
user2492364 Avatar asked Nov 27 '25 10:11

user2492364


1 Answers

Changing the capacity of a StringBuffer after it has been created is more costly than creating it with the expected needed capacity.

Use this constructor to remove this warning:

    /**
     * Constructs a string buffer with no characters in it and
     * the specified initial capacity.
     *
     * @param      capacity  the initial capacity.
     * @exception  NegativeArraySizeException  if the <code>capacity</code>
     *               argument is less than <code>0</code>.
     */
    public StringBuffer(int capacity) {
        super(capacity);
    }
like image 134
cahen Avatar answered Nov 30 '25 00:11

cahen



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!