package com.yfd.monitor.utils;

import java.util.*;
import java.util.stream.Collectors;

public class Test {
    public static void main(String[] args) {
        List<Map<String, Object>> list = new ArrayList<>();
        Map<String, Object> map1 = new HashMap<>();
        map1.put("key", "value1");

        Map<String, Object> map2 = new HashMap<>();
        map2.put("key", "value2");

        Map<String, Object> map3 = new HashMap<>();
        map3.put("key", "value1");

        list.add(map1);
        list.add(map2);
        list.add(map3);

        // 提取需要去重的字段，并去重
        Set<Object> uniqueKeys = new HashSet<>();
        List<Map<String, Object>> uniqueList = list.stream()
                .filter(map -> uniqueKeys.add(map.get("key")))
                .collect(Collectors.toList());

        // 输出结果
        System.out.println("Original List:");
        list.forEach(System.out::println);

        System.out.println("\nUnique List:");
        uniqueList.forEach(System.out::println);
    }
}
