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?
Asked
Active
Viewed 102 times
0
-
2`ArrayList` maybe? https://docs.oracle.com/javase/7/docs/api/java/util/ArrayList.html – Maljam Apr 22 '16 at 01:50
-
Appending using .add(object) with `ArrayList`? – Andrew Li Apr 22 '16 at 01:50
1 Answers
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