Reputation: 8711
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.
Upvotes: 0
Views: 670
Reputation: 692271
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.
Upvotes: 3