Skip to content

Tag: collections

Create a list with only base class elements

In Java I have a class and subclass Now let’s say I have List<Bar> bars. How can I create from this a List of Foo (and I only want the a field to appear, not b) Answer What you want is impossible; let’s say you have your bars list which contains 5 Bar instances. It is not possible in java

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-insens…