m0_46212244
shallow丶十三
2021-01-23 10:59

怎么将一个list集合里的n多个对象数据根据对象数据的某个字段名的值相同归为一个新的对象?

  • intellij-idea

比如:返回的数据格式是[{"id":"1", "name":"lisi","age":18,......},{"id":"2", "name":"wanger","age":18,......},{"id":"3", "name":"zhangsan","age":23,......},{"id":"1", "name":"liuqie","age":12,......},{"id":"2", "name":"ningba","age":19,......}]就是将id一样的放在一起,返回的格式是[{{"id":"1", "name":"lisi","age":18,......},{"id":"1", "name":"liuqie","age":12,......}},{{"id":"2", "name":"wanger","age":18,......},{"id":"2", "name":"ningba","age":19,......}},{"id":"3", "name":"zhangsan","age":23,......}]我试过用stream流写过,他返回的map集合不行,不适合,他分组出来会带key以及将id一样的变成list集合格式,求大神指教

  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

14条回答