Skip to content

Tag: treemap

How to match equals() and hashCode in streams?

I have a stream where I am aggregating some data like this: The problem is that by adding this comparator I am braking the contract between hashCode() and equals() and at the end I have duplicate keys: Has anyone some ideas how can I fix this? Or is there a way to sort the final object ( Map<String, Map<String, Map<EventType,

putting value in Treemap understanding issues

I was running through a leetcode problem. and found a solution in the discussion section problem- https://leetcode.com/problems/stock-price-fluctuation/ solution- but I do not understand the following parts. if someone could explain that would be great Answer To solve the problem you need to know how often the stock is traded for a particular price. An example: it was traded at timestamp

Comparing the contents of two Treemaps

I have two TreeMaps that I want to compare. I currently have it written down like below but I feel like this could be written more efficiently. I tried looking in to comparators, but I don’t think that’s something I can use for my use-case. The maps are Treemaps because the key must be case-insensitive. Thanks in advance Answer If

Find element position in a Java TreeMap

I am working with a TreeMap of Strings TreeMap<String, String>, and using it to implement a Dictionay of words. I then have a collection of files, and would like to create a representation of each file in the vector space (space of words) defined by the dictionary. Each file should have a vector representing it with following properties: vector should