0

I have an array of images created in Java, but as my code creates more, Id like to add them to my already created array. What methods are available to add these new images to my array?

Gee Boughuski
  • 53
  • 1
  • 6

1 Answers1

2

Java arrays are always a fixed size; once you have an array you cannot resize it. System.arrayCopy() allows you to copy the contents of an array to a new (potentially larger) array, however even that is too manual.

The Collections API provides a number of higher-level data structures that are more user-friendly than arrays, including the List interface which defines an API similar to arrays but has many additional features including the ability to be resized, and ArrayList, a List implementation that is backed by arrays under the covers.

In short, if you need a resizable array, you really want an ArrayList.

dimo414
  • 47,227
  • 18
  • 148
  • 244