In this post, we will see how to resolve Java-Stream – How to apply sorting while using Collector groupingBy Question: I’m using Collectors.groupingBy to group may objects into list. Examples are as follows: Output: But my goal is to sort ...

Question: I’m working on a solution including 2 types of sorting based on a property. What do you think which one is a better approach? or is better having 2 classes with their own logic and choosing one in the ...

Question: I have been able to get the array so that it is sorted using ‘m’, but the results are in defending order – as in all strings that contain ‘m’ are at the end. My print out reads; I ...

Question: I have taken a treemap and want to sort it according to its key values which are stored in a hashmap. Whenever I want to update a key-value pair, I remove the key from the tree and add the ...

Question: Essentially I am looking for an efficient way to implement custom comparators using heapq. For instance x = [('a',5),('c',3),('d',2),('e',1)] I could heapify it heapq.heapify(x) then pop the min value heapq.heappop(x) which would return ('a', 5). How can I make ...

Question: Essentially I am looking for an efficient way to implement custom comparators using heapq. For instance x = [('a',5),('c',3),('d',2),('e',1)] I could heapify it heapq.heapify(x) then pop the min value heapq.heappop(x) which would return ('a', 5). How can I make ...

Question: Hello. I want to sort a newly created LinkedList ascending, all elements of the list are crated randomly. My task is to sort them with a Comparator, but I am not allowed to write a class that implements Comparator, ...

Question: I am new to C++ and still learning the concepts. I am trying to pass a priority queue with custom comparators to a templated function. I want to abstract the comparator type in priority queue template argument list when ...

Question: I am trying to sort a list of LeaveRequest by it’s User name, but it is not working. The resulting list is not ordered based on User’s name and it seems not to be affected by the sorted() method. ...