Search code examples
javacollectionsjava-8fastutil

How to convert map to biglist?


How to convert java.util.Map to fastutil.BigList?

BigList<Employee> empList= empMap.values().stream().collect(Collectors.toList());


Solution

  • I see that BigList is an interface that extends java.util.Collection. You can use Collectors.toCollection to collect to this type.

    You'll have to choose a specific class that implement the BigList interface. For example:

    BigList<Employee> empList = 
        empMap.values()
              .stream()
              .collect(Collectors.toCollection(ReferenceBigArrayBigList::new));
    

    Of course, if the BigList implementation you wish to create has a constructor that accepts a Collection, you can simply instantiate it yourself and pass empMap.values() to it without using Streams.