Mutliple Arraylist<>有10条记录。我已经使用这样来限制最多10个结果,但是如何获得接下来的10个结果等等。
try {
ArrayList<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();
List<?> eventsToday = (List<?>) filter.filter(calendar.getComponents(Component.VEVENT));
CalanderQueryOutput caldavOutput = new CalanderQueryOutput();
for (Iterator<?> i = eventsToday.iterator(); i.hasNext();) {
if(Limit < RsLimit){
results.add(caldavOutput);
Limit++;
}
}
}
答案 0 :(得分:3)
首先你需要一些其他数据结构来存储多个arraylists,你可以使用列表列表
List<List<CalanderQueryOutput>> resultList = new ArrayList<List<CalanderQueryOutput>>();
List<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();
for (Iterator<?> i = eventsToday.iterator(); i.hasNext();) {
if(Limit < RsLimit){
results.add(caldavOutput);
Limit++;
}else{
resultList.add(results);
Limit = 0;
results = new ArrayList<CalanderQueryOutput>();
}
}
}
答案 1 :(得分:0)
我修改了我的代码,该代码适用于带有迭代器
的ArrayList int inc = 0;
int IOF = Integer.parseInt(ItemOffset);
inc = IOF;
int IC = Integer.parseInt(ItemCount);
int TotalLimit = 0;
int EventLimit = 0;
for (int l = 0; l < IC; ++l) {
++IOF;
EventLimit = IOF;
}
try {
ArrayList<CalanderQueryOutput> results = new ArrayList<CalanderQueryOutput>();
List<?> eventsToday = (List<?>)filter.filter(calendar.getComponents(Component.VEVENT));
CalanderQueryOutput caldavOutput = new CalanderQueryOutput();
for (Iterator<?> i = eventsToday.iterator(); i.hasNext();) {
if (TotalLimit < eventsToday.size()) {
if (TotalLimit >= inc && TotalLimit <= EventLimit - 1){
results.add(caldavOutput);
}
TotalLimit++;
}
}catch (SardineException e){
}