当前位置:网站首页>Int array get duplicate data
Int array get duplicate data
2022-07-25 13:34:00 【Turn over the troubled times】
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));
}
// Method 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()));// grouping list Display total
List<Integer> result = collect.entrySet().stream()
.filter(e -> e.getValue() > 1) // The total is greater than 1 Filter
.map(Map.Entry::getKey) // Get value transfer list
.collect(Collectors.toList());
int[] a = new int[result.size()];
// Set array
for (int i = 0; i < a.length; i++) {
a[i] = result.get(i);
}
return a;
}
}
边栏推荐
- Mutex lock, spin lock, read-write lock... Clarify their differences and applications
- R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
- [Video] visual interpretation of Markov chain principle and Mrs example of R language region conversion | data sharing
- Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
- 全网最简单解决方式1045-Access denied for user [email protected](using password:YES)
- 从输入网址到网页显示
- 基于百问网IMX6ULL_PRO开发板驱动AP3216实验
- 刷题-洛谷-P1035 级数求和
- 0710RHCSA
- Excel record macro
猜你喜欢

Based on Baiwen imx6ull_ Ap3216 experiment driven by Pro development board

Excel添加按键运行宏

The whole process of 6w+ word recording experiment | explore the economical data storage strategy of alluxio

0710RHCSA

What is your revenue rank among global developers in 2022?

领域驱动模型设计与微服务架构落地-模型设计

【CTR】《Towards Universal Sequence Representation Learning for Recommender Systems》 (KDD‘22)

刷题-洛谷-P1059 明明的随机数
HTTP cache tongtianpian, there may be something you want

How to solve the problem of taking up too much space when recording and editing videos?
随机推荐
JS array indexof includes sort() colon sort quick sort de duplication and random sample random
我的创作纪念日
基于百问网IMX6ULL_PRO开发板驱动AP3216实验
VIM basic operation summary
刷题-洛谷-P1059 明明的随机数
Hcip day 10 notes
6W+字记录实验全过程 | 探索Alluxio经济化数据存储策略
6.27 uniapp项目历程
0710RHCSA
Excel import and export source code analysis
Prepare for 2022 csp-j1 2022 csp-s1 preliminaries video set
刷题-洛谷-P1075 质因数分解
hcip第八天笔记
Excel添加按键运行宏
ThreadLocal&Fork/Join
hcip第六天笔记
In order to improve efficiency, there are various problems when using parallelstream
QingChuang technology joined dragon lizard community to build a new ecosystem of intelligent operation and maintenance platform
mujoco+spinningup进行强化学习训练快速入门
MLIR原理与应用技术杂谈