0

This code you have seen returns only the first 3 of the elements whose originator id is 1. Then I want it to switch and return 3 elements with other orginator id 1, how can I do this using Stream? Then I want it to go back and re-read it if it's available and send it as a message.

List<BulkSmsTest> bulkSms = new ArrayList<>();
bulkSms.add(new BulkSmsTest("message", "+994000000000", 1));
bulkSms.add(new BulkSmsTest("message", "+994000000001", 1));
bulkSms.add(new BulkSmsTest("message", "+994000000002", 1));
bulkSms.add(new BulkSmsTest("message", "+994000000003", 1));
bulkSms.add(new BulkSmsTest("message", "+994000000004", 1));
bulkSms.add(new BulkSmsTest("message", "+994000000005", 1));
bulkSms.add(new BulkSmsTest("message", "+994775287264", 2));
bulkSms.add(new BulkSmsTest("message", "+994775287264", 3));
bulkSms.add(new BulkSmsTest("message", "+994775287264", 4));
bulkSms.add(new BulkSmsTest("message", "+994775287264", 5));


List<BulkSmsTest> list = bulkSms.stream().filter(bulkSmsTest -> bulkSmsTest.getOriginatorId() == 1)
        .limit(3)
        .collect(Collectors.toList())
list.forEach(System.out::println);
Naman
  • 21,685
  • 24
  • 196
  • 332
Anar Məmmədov
  • 137
  • 2
  • 9
  • If I am able to understand you right, you are looking for batching the list using streams. This might be of help - https://stackoverflow.com/questions/30641383/java-8-stream-with-batch-processing – Naman Oct 28 '21 at 14:39

0 Answers0