I want to convert this java do...while() to a Java 8.
private static final Integer PAGE_SIZE = 200;
int offset = 0;
Page page = null;
do {
// Get all items.
page = apiService.get(selector);
// Display items.
if (page.getEntries() != null) {
for (Item item : page.getEntries()) {
System.out.printf("Item with name '%s' and ID %d was found.%n", item.getName(),
item.getId());
}
} else {
System.out.println("No items were found.");
}
offset += PAGE_SIZE;
selector = builder.increaseOffsetBy(PAGE_SIZE).build();
} while (offset < page.getTotalNumEntries());
This code makes api call to apiService
and retrieves data. Then, I want to loop until offset is less than totalNumberEntries
.
What is prohibiting me from using while()
or foreach with step
or any other kind of loop
loop is I don't know the totalNumberEntries
without making API call (which is done inside the loop).
One option I can think of is making the API call just to get the totalNumberEntries
and proceed with the loop.