list数组排序---stream
import java.util.*;
import java.util.stream.Collector;
import java.util.stream.Collectors; public class ListAnum {
public static void main(String[] args){
List<Integer> list = new ArrayList<>();
list.add(1);
list.add(99);
list.add(9);
list.add(2);
list.add(1);
list.add(99);
list.add(99);
list.add(23);
list.add(1);
list.add(00);
list.add(432);
list.add(43222);
list.add(22);
list.add(99);
list.add(2);
list.add(212);
//Map<Integer,Long> map = list.stream().collect(Collectors.groupingBy(p ->p,Collectors.counting()));
//map.forEach((k,v) -> System.out.println(k+":"+v));
Map<Integer,Long> map = list.stream().collect(Collectors.groupingBy(e->e,Collectors.counting()));
Map<Integer,Long> map1 = new LinkedHashMap<>();
//通过value排序
//map.entrySet().stream().sorted(Map.Entry.comparingByValue()).forEachOrdered(e->map1.put(e.getKey(),e.getValue()));
//通过key排序
map.entrySet().stream().sorted(Map.Entry.comparingByKey()).forEachOrdered(e->map1.put(e.getKey(),e.getValue()));
System.out.println(map1); }
}
list数组排序---stream的更多相关文章
- [LeetCode] Find Median from Data Stream 找出数据流的中位数
Median is the middle value in an ordered integer list. If the size of the list is even, there is no ...
- Find Median from Data Stream 解答
Question Median is the middle value in an ordered integer list. If the size of the list is even, the ...
- C#字符串数组排序 C#排序算法大全 C#字符串比较方法 一个.NET通用JSON解析/构建类的实现(c#) C#处理Json文件 asp.net使用Jquery+iframe传值问题
C#字符串数组排序 //排序只带字符的数组,不带数字的 private string[] aa ={ "a ", "c ", "b & ...
- 【Java必修课】一图说尽排序,一文细说Sorting(Array、List、Stream的排序)
简说排序 排序是极其常见的使用场景,因为在生活中就有很多这样的实例.国家GDP排名.奥运奖牌排名.明星粉丝排名等,各大排行榜,给人的既是动力,也是压力. 而讲到排序,就会有各种排序算法和相关实现,本文 ...
- java 集合数组排序
//数组排序Integer arr[] = {3,4,2};Arrays.sort(arr);//默认升序Arrays.sort(arr,Comparator.reverseOrder());//传一 ...
- SQL Server-聚焦查询计划Stream Aggregate VS Hash Match Aggregate(二十)
前言 之前系列中在查询计划中一直出现Stream Aggregate,当时也只是做了基本了解,对于查询计划中出现的操作,我们都需要去详细研究下,只有这样才能对查询计划执行的每一步操作都了如指掌,所以才 ...
- Node.js:理解stream
Stream在node.js中是一个抽象的接口,基于EventEmitter,也是一种Buffer的高级封装,用来处理流数据.流模块便是提供各种API让我们可以很简单的使用Stream. 流分为四种类 ...
- node中的Stream-Readable和Writeable解读
在node中,只要涉及到文件IO的场景一般都会涉及到一个类-Stream.Stream是对IO设备的抽象表示,其在JAVA中也有涉及,主要体现在四个类-InputStream.Reader.Outpu ...
- CSharpGL(36)通用的非托管数组排序方法
CSharpGL(36)通用的非托管数组排序方法 如果OpenGL要渲染半透明物体,一个方法是根据顶点到窗口的距离排序,按照从远到近的顺序依次渲染.所以本篇介绍对 UnmanagedArray< ...
随机推荐
- vue学习笔记(1)
1.检测变化 <ul> <li v-for="item in list">{{item}}</li> </ul> <scrip ...
- bzoj 1649: [Usaco2006 Dec]Cow Roller Coaster【dp】
DAG上的dp 因为本身升序就是拓扑序,所以建出图来直接从1到ndp即可,设f[i][j]为到i花费了j #include<iostream> #include<cstdio> ...
- 微信小程序-wepy-组件模板重复渲染
微信小程序开发,有使用wepy框架的需求.上手: 安装自己可以到官网查看,飞机票:https://tencent.github.io/wepy/document.html#/ 具体开发模式和Vue开发 ...
- spring cloud config搭建说明例子(一)-简单示例
服务端 ConfigServer pom.xml添加config jar <dependency> <groupId>org.springframework.cloud< ...
- 洛谷2019 3月月赛 T4
T3做不来.. 直接滚去T4 orz 乍一看 T4是个DP 题干 复杂度??(N^4) 咋优化... 还带一只捆绑 捆绑啥的最烦人了 最后20pts 直接废了 T了 很烦 不过拿到80pts已经很开心 ...
- 题解报告:poj 1426 Find The Multiple(bfs、dfs)
Description Given a positive integer n, write a program to find out a nonzero multiple m of n whose ...
- c++自动导出lua绑定
cocos 使用bindings-generator脚本代替了toLua++. 编写效率大大提高. 具体的在本机中分享:http://note.youdao.com/noteshare?id=0f41 ...
- multiprocessing的进程通信Pipe和Queue
pipe管道,2个进程通信,允许单项或者双向,multiprocessing.Pipe(duplex=False)为单项,默认双向 示例: from multiprocessing import Pr ...
- JSON基础 JS操作JSON总结
JSON(JavaScript Object Notation) 是一种轻量级的数据交换格式,采用完全独立于语言的文本格式,是理想的数据交换格式.同时,JSON是 JavaScript 原生格式,这意 ...
- TCPClient、TCPListener的用法
支持Http.Tcp和Udp的类组成了TCP/IP三层模型(请求响应层.应用协议层.传输层)的中间层-应用协议层,该层的类比位于最底层的Socket类提供了更高层次的抽象,它们封装 TCP 和 UDP ...