Reputation: 161
Let's say I want to make an app, where the user can add colors to a list, so I don't know how many colors there's gonna be. When the user is adding a color to the list, he/she also wants to type the colors which can be combined to make the decided color.
However I don't know in advance how many options the user needs, as it's different from color to color. Therefore, I think an array isn't an option (correct me if I'm wrong). Also, when the user search for blue or yellow, the app should give back green, as those combine to green.
I don't want you to write my code, so if you can just give me some reference where I can learn more, I'd be very pleased.
Upvotes: 1
Views: 100
Reputation: 5134
You can use ArrayList. There is no need to specify size in ArrayList. You can add as many as you want.
ArrayList<Collection> color = new ArrayList<Collecton>();
Here your Collection type consist of all the attributes you want in your color
Upvotes: 1
Reputation: 121998
Forget about arrays, and learn Collections
in java.
Just have l look at List interface
and some implemented class of it, like ArrayList
.
An ArrayList is by definition
Resizable-array implementation of the List interface
Upvotes: 3