I have a Deque from Integers, which I'm using as a Que. I have to add and remove elements from it and in some cases I need to print the max value in the Que.
The thing that I've tried is:
System.out.println(deque.stream().max(Integer::compareTo));
But it prints - Optional[the current max int].
Thank you!
That is because the
maxmethod ofjava.util.Streamreturns your value wrapped inOptional. This is the signature of the max methodOptional<T> max(Comparator<? super T> comparator);The example below would provide you the expected behaviour: