Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class GrowingArray
- {
- Object[] array;
- int count;
- int capacity;
- public void appending(Object obj)
- {
- // grow array if needed
- if (count == capacity)
- {
- int i, newLen = capacity + 3; /* 3 is an arbitrary increment here */
- Object[] newArray = new Object[newLen];
- for (i = 0; i < count; ++i) // copy items
- {
- newArray[i] = array[i];
- }
- array = newArray;
- }
- array[count] = obj;
- ++count;
- }
- }
Add Comment
Please, Sign In to add comment