How do you add images to an array?

Also, in what kind of array you want to store that Picture object. In a Picture[] array, a byte[] array, or . ?

Commented May 1, 2013 at 16:24 @kocko: No need to nitpick. You can easily assume that they want to store it in a Picture[] array. Commented May 1, 2013 at 16:41

I forgot to put that this is in java but thanks for the feedback everyone, it was useful and helped me

Commented May 1, 2013 at 19:01

3 Answers 3

Java is object-oriented, which lets you take advantage of polymorphism to reuse code and concepts. Since Picture extends Object you can store it in an array like you would any other object.

Picture[] pictures = new Picture[10]; pictures[0] = pictureToAdd; 

If you want to iterate through the array you can do:

for(Picture picture : pictures) < // do stuff here >

You can also put Picture objects into an ArrayList or any other data structure.

List pictures = new ArrayList(); pictures.add(pictureToAdd);