【发布时间】:2016-04-11 06:30:03
【问题描述】:
我创建了两个类,Waitlist 和 Party。 Waitlist 类将与LocalTimes 列表一起使用,并为每个LocalTime 分配多个Partys。我不清楚我是否应该创建一个LocalTimes 数组和一个Party[]s 数组,或者我是否应该以某种方式使用ArrayLists,或者在这种情况下HashMap 是否是一个不错的选择。
Waitlist.java
public class Waitlist {
private static final int N = 74;
private LocalTime[] times;
private ArrayList<Party>[] slots;
private HashMap<LocalTime, ArrayList<Party>[]> list;
public Waitlist() {
// initialize variables
//init `times`
times = new LocalTime[N];
slots = new ArrayList[N];
int h = 9; // open
int m = 0;
for (int i = 0; i < N; i++) {
slots[i] = new ArrayList<>();
times[i] = LocalTime.of(h, m);
if (m == 48) {
h++;
m = 0;
} else {
m += 12;
}
}
}
}
【问题讨论】:
-
数组和列表本质上是一回事。两者都与
Map非常不同,后者可能代表一种关系。花一些时间研究和理解基本数据结构和示例用例 - 如果没有这些理解基础,我们将不清楚如何更好地为您解释差异。
标签: java arrays arraylist hashmap