我设计并编写了一个名为FrequencyData的类:
public class FrequencyData {
char letter;
int frequency;
public FrequencyData(char in_pointer, int in_frequency) {
frequency = in_frequency;
letter = in_pointer;
}
public char getLetter() {
return letter;
}
public int getFrequency() {
return frequency;
}
}
我知道如何创建我的班级实例:
FrequencyData info = new FrequencyData('c', 5);
如何创建数组列表并将此实例添加到其中,以及稍后的其他实例?
答案 0 :(得分:3)
假设您正在讨论使用java中的FrequencyData类型的成员模板化ArrayList类,
FrequencyData info = new FrequencyData('c', 5);
ArrayList<FrequencyData> list = new ArrayList<FrequencyData>();
list.add(info);