So, based on your description, I think the filter you want is this:

segments.stream()
        .filter(m -> ((Long) m.get("ct")) != 1L)
        .collect(toList());

Or being explicit about the type of the predicate:

        .filter((Map<String, Object> m) ->
                    ((Long) m.get("ct")) != 1L)

On your edit: you have erroneous data in the Map, or you've misunderstood the way it's represented. It appears that segments is actually a List<Object[]>.

I don't really have enough information to help you fix it.

To try debugging, you could do something like:

segments.stream()
        .map(Arrays::toString)
        .forEach(System.out::println);

This will tell you what's actually in it if you don't have documentation to refer to.

Answer from Radiodef on Stack Overflow
Discussions

Java 8 Filter Map<String,List<Employee>> - Stack Overflow
Also i have to filter out the key in the output map (or filter map [new map we get after filter]) if the List<> is empty on the map value ... Please add some more detail: What do you mean by filter (remove/keep the employees with/without M or remove/keep the lists that have at least one/only ... More on stackoverflow.com
🌐 stackoverflow.com
Using Java stream to filter a list and create a map - Code Review Stack Exchange
In List , I'd like to extract Hotels which has OTAProperty with a specific otaName, as Map . The map's key is the id for the OTAProperty named given otaName, and the v... More on codereview.stackexchange.com
🌐 codereview.stackexchange.com
java - Map to List after filtering on Map's key using Java8 stream - Stack Overflow
Communities for your favorite technologies. Explore all Collectives · Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work More on stackoverflow.com
🌐 stackoverflow.com
iterator - Java 8 - Filter list inside map value - Stack Overflow
I am writing a method which takes an input Map of the form Map where a Term is defined here. Method: Go over the keys of the Map and filter them using a Term attri... More on stackoverflow.com
🌐 stackoverflow.com
March 25, 2016
🌐
DZone
dzone.com › coding › languages › java 8 map, filter, and collect examples
Java 8 Map, Filter, and Collect Examples - DZone
June 21, 2018 - Learn how to use the map() function in Java 8 to transform an object to another and how to use the filter() to select an object based upon condition.
🌐
Blogger
javarevisited.blogspot.com › 2018 › 05 › java-8-filter-map-collect-stream-example.html
How to use filter + map + collect + Stream in Java? Example Tutorial
May 22, 2018 - Once we got the Stream of Integer, we can apply maths to find out even numbers, and we passed that condition to the filter method. If we needed to filter on String, like select all string which has length > 2 then we would have called filter before map. That's all about how to use map and filter in Java 8.
Top answer
1 of 7
6

To filter out entries where a list contains an employee who is not of the "M" gender:

Map<String, List<Employee>> r2 = map.entrySet().stream()
    .filter(i -> i.getValue().stream().allMatch(e-> "M".equals(e.gender)))
    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

To filter out employees who are not of the "M" gender:

Map<String, List<Employee>> r1 = map.entrySet().stream()
    .filter(i -> !i.getValue().isEmpty())
    .collect(Collectors.toMap(Map.Entry::getKey,
        i -> i.getValue().stream()
              .filter(e -> "M".equals(e.gender)).collect(Collectors.toList())));

To filter out entries where a list doesn't contain any "M" employee.

Map<String, List<Employee>> r3 = map.entrySet().stream()
    .filter(i -> i.getValue().stream().anyMatch(e -> "M".equals(e.gender)))
    .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

Let's have 2 entries in the map:

"1" -> ["M", "M", "M"]
"2" -> ["M", "F", "M"]

The results for them will be:

r1 = {1=[M, M, M], 2=[M, M]}
r2 = {1=[M, M, M]}
r3 = {1=[M, M, M], 2=[M, F, M]}
2 of 7
1

In Java 8 you can convert a Map.entrySet() into a stream, follow by a filter() and collect() it. Example taken from here.

    Map<Integer, String> map = new HashMap<>();
    map.put(1, "linode.com");
    map.put(2, "heroku.com");

    //Map -> Stream -> Filter -> String
    String result = map.entrySet().stream()
        .filter(x -> "something".equals(x.getValue()))
        .map(x->x.getValue())
        .collect(Collectors.joining());

    //Map -> Stream -> Filter -> MAP
    Map<Integer, String> collect = map.entrySet().stream()
        .filter(x -> x.getKey() == 2)
        .collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));

    // or like this
    Map<Integer, String> collect = map.entrySet().stream()
        .filter(x -> x.getKey() == 3)
        .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue));

And for your case it would look like this, because you also need to find out if there is a match in a List of object of class Employee.

Map<String, List<Employee>> collect = map.entrySet().stream()
            .filter(x -> x.getValue().stream()
        .anyMatch(employee -> employee.Gender.equals("M")))
            .collect(Collectors.toMap(x -> x.getKey(), x -> x.getValue()));
🌐
Mkyong
mkyong.com › home › java8 › java 8 map filter examples
Java 8 Map filter examples | mkyong.com
March 13, 2024 - package com.mkyong.examples; import java.util.HashMap; import java.util.Map; import java.util.stream.Collectors; public class MapFilterExample2 { public static void main(String[] args) { Map<Integer, String> map = new HashMap<>(); map.put(1, "linode"); map.put(2, "heroku"); map.put(3, "aws"); //Map -> Stream -> Filter -> String String result1 = map.values().stream() .filter("linode"::equals) .collect(Collectors.joining()); // linode System.out.println(result1); //Map -> Stream -> Filter -> MAP Map<Integer, String> result2 = map.entrySet().stream() .filter(x -> x.getKey() == 1) .collect(Collect
🌐
BeginnersBook
beginnersbook.com › 2017 › 10 › java-8-filter-a-map-by-keys-and-values
Java 8 – Filter a Map by keys and values
import java.util.Map; import java.util.HashMap; import java.util.stream.Collectors; public class Example { public static void main(String[] args) { Map<Integer, String> hmap = new HashMap<Integer, String>(); hmap.put(1, "ABC"); hmap.put(2, "XCB"); hmap.put(3, "ABB"); hmap.put(4, "ZIO"); Map<Integer, String> result = hmap.entrySet() .stream() .filter(p -> p.getKey().intValue() <= 2) //filter by key .filter(map -> map.getValue().startsWith("A")) //filter by value .collect(Collectors.toMap(map -> map.getKey(), map -> map.getValue())); System.out.println("Result: " + result); } }
🌐
Java Code Geeks
javacodegeeks.com › home › core java
Java 8 filter & map & collect & Stream Example - Java Code Geeks
May 21, 2018 - Now you may be thinking how does it know to return List of Integer, well it get that information by Type inference because we have already specified that by storing the result into a List<Integer>. Here is the Java program to implement whatever I have said in the above section. You can run this program in IDE or from the command line and see the result. You can also experiment with using more map() function or more filter() calls to make the composition longer and more sophisticated.
Find elsewhere
🌐
Medium
medium.com › javarevisited › how-to-use-streams-map-filter-and-collect-methods-in-java-1e13609a318b
How to use map, filter, and collect methods in Java Stream? Example Tutorial | by javinpaul | Javarevisited | Medium
January 25, 2024 - That’s all about how to use map and filter in Java 8. We have seen an interesting example of how we can use the map to transform an object to another and how to use the filter to select an object-based upon condition.
🌐
Baeldung
baeldung.com › home › java › java collections › java map › how to convert list to map in java
How to Convert List to Map in Java | Baeldung
April 4, 2025 - Get started with understanding multi-threaded applications with our Java Concurrency guide: ... Since its introduction in Java 8, the Stream API has become a staple of Java development. The basic operations like iterating, filtering, mapping sequences of elements are deceptively simple to use.
🌐
javathinking
javathinking.com › blog › java-8-lambda-convert-list-to-map
Java 8 Lambda: Convert List to Map — javathinking.com
Before converting a List to a Map, filter out any null keys or values to avoid NullPointerException. Java 8 lambda expressions and the Stream API provide a powerful and concise way to convert a List to a Map.
🌐
JRebel
jrebel.com › blog › using-java-stream-map-and-java-stream-filter
Using Java 8 Stream Map and Java 8 Stream Filter | JRebel
June 25, 2025 - Further in this post we'll show how to filter a list or set a Java 8 stream filter and how to convert a stream to a regular set or a list.Back to top · The new java.util.stream package has been added to JDK which allows us to perform filter/map/reduce-like operations with the Java 8 collections stream.
🌐
How to do in Java
howtodoinjava.com › home › java streams › how to filter a map by list of keys in java
How to Filter a Map by List of Keys in Java
September 16, 2022 - Java 8, Java 8 Stream, Stream Filter · Learn to filter a Map by keys or values using forEach() loop and Stream.filter() API in Java 8. For the code examples, we will use the following Map of users.
🌐
amitph
amitph.com › home › java › using filter on stream of maps in java
Using Filter on Stream of Maps in Java - amitph
November 22, 2024 - We have used Java Streams to specify a predicate to filter Map elements and collect the filtered elements in a new HashMap or collect the filtered values into a List. We have also created a Java Stream based generic filter function that can be reused to filter Map elements based on a predicate.