Let's say we have a Queue
BlockingQueue<String> queue= new LinkedBlockingQueue<>();
and some other thread puts values in it, then we read it like
while (true) {
String next = queue.take();
System.out.println("next message:" + next);
}
How can I iterate over this queue in stream style, while maintaining similar semantics to above code.
This code only traverses the current queue state:
queue.stream().forEach(e -> System.out.println(e));