当前位置:网站首页>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;
}
}
边栏推荐
- 需求规格说明书模板
- 【AI4Code】《Unified Pre-training for Program Understanding and Generation》 NAACL 2021
- Eccv2022 | transclassp class level grab posture migration
- [ai4code final chapter] alphacode: competition level code generation with alphacode (deepmind)
- 工业互联网的内涵及其应用
- Cyberspace Security penetration attack and defense 9 (PKI)
- Mlx90640 infrared thermal imager temperature sensor module development notes (V)
- Mid 2022 review | latest progress of large model technology Lanzhou Technology
- 业务可视化-让你的流程图'Run'起来(3.分支选择&跨语言分布式运行节点)
- Seven lines of code made station B crash for three hours, but "a scheming 0"
猜你喜欢

Convolutional neural network model -- googlenet network structure and code implementation
![[CSDN year-end summary] end and start, always on the way -](/img/51/a3fc5eba0eeb22b600260ee81ff9e6.png)
[CSDN year-end summary] end and start, always on the way - "2021 summary of" 1+1= Wang "

Excel录制宏

Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘

【GCN-CTR】DC-GNN: Decoupled GNN for Improving and Accelerating Large-Scale E-commerce Retrieval WWW22

Common operations for Yum and VIM

arm架构移植alsa-lib和alsa-utils一路畅通

Atcoder beginer contest 261e / / bitwise thinking + DP
详解浮点数的精度问题

6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
随机推荐
Mlx90640 infrared thermal imager temperature sensor module development notes (V)
TCP的拥塞控制
Emqx cloud update: more parameters are added to log analysis, which makes monitoring, operation and maintenance easier
Substance designer 2021 software installation package download and installation tutorial
7行代码让B站崩溃3小时,竟因“一个诡计多端的0”
pytorch创建自己的Dataset加载数据集
Date and time function of MySQL function summary
二叉树基本知识
MySQL remote connection permission error 1045 problem
The world is exploding, and the Google server has collapsed
[machine learning] experimental notes - emotion recognition
Zero basic learning canoe panel (12) -- progress bar
Jupyter Notebook介绍
Convolutional neural network model -- googlenet network structure and code implementation
EMQX Cloud 更新:日志分析增加更多参数,监控运维更省心
Shell常用脚本:判断远程主机的文件是否存在
[figure attack and Defense] backdoor attacks to graph neural networks (sacmat '21)
go : gin 自定义日志输出格式
[operation and maintenance, implementation of high-quality products] interview skills for technical positions with a monthly salary of 10k+
我的创作纪念日