java - Combining a static array with a dynamic ArrayList -
i want combine static array (such int[]
) dynamic array such arraylist<string>
for example, know count of houses: 10 (fixed), don't know count of humans live in house. count change dynamically, list
.
is there option create datatype can fulfill both criteria?
an arraylist
dynamicly sized data structure backed array. sounds me have array of house
each house
has list<human>
field.
house[] homes = new house[10];
and class like
class house { private list<human> people = new arraylist<>(); public list<human> getpeople() { return people; } }
then total count of people in homes might use like
int count = 0; (house h : homes) { count += h.getpeople().size(); }
Comments
Post a Comment