1

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.

1
  • You're looking for the wonders of collections. Commented Dec 25, 2013 at 17:13

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.