I have a utility class "Utility" that contains two lists:
private static final List<SpreadSheetRecord> DISPLAY = new ArrayList<SpreadSheetRecord>();
private static final List<SpreadSheetRecord> PREVLIST = new ArrayList<SpreadSheetRecord>();
These have getter methods:
public static List<SpreadSheetRecord> getDisplayList() {
return DISPLAY;
}
public static List<SpreadSheetRecord> getPreviousInstanceSSList() {
return PREVLIST;
}
PREVLIST is populated with a list of beans (SpreadSheetRecord) in a static{} block of the Utility class, whilst DISPLAY is populated in another class.
This other class (jframe) gets these references thus:
List<SpreadSheetRecord> displayList = Utility.getDisplayList();
List<SpreadSheetRecord> previousList = Utility.getPreviousInstanceSSList();
At this point previousList could have any number of elements and displayList has none. During execution I need to copy the elements from previousList into displayList based on user request, however I get errors saying that displayList is not big enough. ok so I change it from Collections.copy to a for loop:
for (SpreadSheetRecord s: previousList) {
displayList.add(s);
}
However I get further errors, it won't let me. The only work around I could find was in the Utility class in the static{} block to load the DISPLAY List with say 2000 new objects prior importing to the other class. Then prior to loading in the for loop i call display.List.clear();
It then works fine??? Can someone explain whats going on here as this work around is pants and from some testing I've found that I have to initialise the DISPLAY List to more than the anticipated number I'm going to copy in from previousList.
It works but its not pretty.
Any help would be great.
private static final List<SpreadSheetRecord> DISPLAY = new ArrayList<SpreadSheetRecord>();
private static final List<SpreadSheetRecord> PREVLIST = new ArrayList<SpreadSheetRecord>();
These have getter methods:
public static List<SpreadSheetRecord> getDisplayList() {
return DISPLAY;
}
public static List<SpreadSheetRecord> getPreviousInstanceSSList() {
return PREVLIST;
}
PREVLIST is populated with a list of beans (SpreadSheetRecord) in a static{} block of the Utility class, whilst DISPLAY is populated in another class.
This other class (jframe) gets these references thus:
List<SpreadSheetRecord> displayList = Utility.getDisplayList();
List<SpreadSheetRecord> previousList = Utility.getPreviousInstanceSSList();
At this point previousList could have any number of elements and displayList has none. During execution I need to copy the elements from previousList into displayList based on user request, however I get errors saying that displayList is not big enough. ok so I change it from Collections.copy to a for loop:
for (SpreadSheetRecord s: previousList) {
displayList.add(s);
}
However I get further errors, it won't let me. The only work around I could find was in the Utility class in the static{} block to load the DISPLAY List with say 2000 new objects prior importing to the other class. Then prior to loading in the for loop i call display.List.clear();
It then works fine??? Can someone explain whats going on here as this work around is pants and from some testing I've found that I have to initialise the DISPLAY List to more than the anticipated number I'm going to copy in from previousList.
It works but its not pretty.
Any help would be great.