0

I was wondering if there is a way to store more than 2 elements of information per item in an array of items.

For example, for an array of Cities I would like to store Population (int), Name (String), Mayor (String), Is there an airport (boolean).

I need a modifiable list, e.g. one where I can add and access elements easily by their position.

1
  • wouldnt java.util.List work ?? Commented Nov 4, 2012 at 15:02

1 Answer 1

3

Create a class called City, and containing the necessary fields: population, name, mayor, airportPresent.

Use a java.util.List<City> (java.util.ArrayList being usually the best choice as an implementation).

Java is an OO language. Use objects to store your information, and encapsulate behavior. Using multi-dimensional arrays is not the appropriate solution.

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

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.