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.
Create a class called
City, and containing the necessary fields:population,name,mayor,airportPresent.Use a
java.util.List<City>(java.util.ArrayListbeing 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.