当前位置:网站首页>int数组获取重复数据
int数组获取重复数据
2022-07-25 13:07:00 【翻出乱世】
package com.javaming.study.easyexcel.controller;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;
import static java.util.Arrays.sort;
public class OfferTest {
public static void main(String[] args) {
int[] a = {1, 2, 3, 4, 2, 3,1,12,1};
int[] repeatNumbe2 = findRepeatNumbe2(a);
System.out.println(Arrays.toString(repeatNumbe2));
}
//方法2
public static int[] findRepeatNumbe2(int[] nums) {
List<Integer> numList = new ArrayList<>();
for (int num : nums) {
numList.add(num);
}
Map<Integer, Long> collect = numList.stream()
.collect(Collectors.groupingBy(Function.identity(), Collectors.counting()));//分组list 显示总数
List<Integer> result = collect.entrySet().stream()
.filter(e -> e.getValue() > 1) //总数大于1过滤
.map(Map.Entry::getKey) //获取值转list
.collect(Collectors.toList());
int[] a = new int[result.size()];
//集合转数组
for (int i = 0; i < a.length; i++) {
a[i] = result.get(i);
}
return a;
}
}
边栏推荐
- 网络空间安全 渗透攻防9(PKI)
- [operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
- 6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
- ORAN专题系列-21:主要的玩家(设备商)以及他们各自的态度、擅长领域
- [Video] Markov chain Monte Carlo method MCMC principle and R language implementation | data sharing
- G027-OP-INS-RHEL-04 RedHat OpenStack 创建自定义的QCOW2格式镜像
- 部署Apache网站服务以及访问控制的实现
- Excel添加按键运行宏
- pytorch创建自己的Dataset加载数据集
- 基于百问网IMX6ULL_PRO开发板驱动AP3216实验
猜你喜欢

从输入网址到网页显示

R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions

Zero basic learning canoe panel (12) -- progress bar

Seven lines of code made station B crash for three hours, but "a scheming 0"

Atcoder beginer contest 261 f / / tree array

Atcoder beginer contest 261e / / bitwise thinking + DP
![[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+](/img/d8/90116f967ef0f5920848eca1f55cdc.png)
[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+

Any time, any place, super detective, seriously handle the case!

【OpenCV 例程 300篇】239. Harris 角点检测之精确定位(cornerSubPix)

arm架构移植alsa-lib和alsa-utils一路畅通
随机推荐
Excel添加按键运行宏
Shell常用脚本:检测某域名、IP地址是否通
Migrate PaloAlto ha high availability firewall to panorama
mysql函数汇总之日期和时间函数
程序的内存布局
Atcoder beginer contest 261e / / bitwise thinking + DP
Mid 2022 review | latest progress of large model technology Lanzhou Technology
ESP32-C3 基于Arduino框架下Blinker点灯控制10路开关或继电器组
错误: 找不到或无法加载主类 xxxx
Convolutional neural network model -- lenet network structure and code implementation
ThreadLocal&Fork/Join
Django 2 ----- 数据库与Admin
How to use causal inference and experiments to drive user growth| July 28 tf67
【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020
基于百问网IMX6ULL_PRO开发板驱动AP3216实验
【历史上的今天】7 月 25 日:IBM 获得了第一项专利;Verizon 收购雅虎;亚马逊发布 Fire Phone
JS sorts according to the attributes of the elements in the array
备战2022 CSP-J1 2022 CSP-S1 初赛 视频集
B tree and b+ tree
迁移PaloAlto HA高可用防火墙到Panorama