Guest User

Untitled

a guest
Jan 21st, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. public class GrowingArray
  2. {
  3. Object[] array;
  4. int count;
  5. int capacity;
  6.  
  7. public void appending(Object obj)
  8. {
  9. // grow array if needed
  10. if (count == capacity)
  11. {
  12. int i, newLen = capacity + 3; /* 3 is an arbitrary increment here */
  13. Object[] newArray = new Object[newLen];
  14. for (i = 0; i < count; ++i) // copy items
  15. {
  16. newArray[i] = array[i];
  17. }
  18. array = newArray;
  19. }
  20.  
  21. array[count] = obj;
  22. ++count;
  23. }
  24. }
Add Comment
Please, Sign In to add comment