Avoiding Dynamically Expanding Objects
Many API classes contain buffers that expand as more data is added
Examples: Hashtable, Vector, ArrayList, StringBuffer, Stack, ByteArrayOutputStream
Buffer expansion means allocation of buffer twice the size (or more) + copying of old buffer into new buffer + deallocation of old buffer
General idea:
- either use dynamically expanding object but prevent frequent expansion by initializing object with large internal buffer, or