当前位置:网站首页>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;
}
}
边栏推荐
- 面试官问我:Mysql的存储引擎你了解多少?
- The migration of arm architecture to alsa lib and alsa utils is smooth
- 一味地做大元宇宙的规模,已经背离了元宇宙本该有的发展逻辑
- 全网最简单解决方式1045-Access denied for user [email protected](using password:YES)
- JS array indexof includes sort() colon sort quick sort de duplication and random sample random
- 0710RHCSA
- 0713RHCSA
- MLIR原理与应用技术杂谈
- 0717RHCSA
- 刷题-洛谷-P1089 津津的储蓄计划
猜你喜欢
随机推荐
2022年下半年软考信息安全工程师如何备考?
Brpc source code analysis (III) -- the mechanism of requesting other servers and writing data to sockets
R language GLM generalized linear model: logistic regression, Poisson regression fitting mouse clinical trial data (dose and response) examples and self-test questions
央行数研所穆长春:数字人民币可控匿名是维护公众利益和金融安全的客观需要
The interviewer asked me: how much do you know about MySQL's storage engine?
MLIR原理与应用技术杂谈
Cv2.resize function reports an error: error: (-215:assertion failed) func= 0 in function ‘cv::hal::resize‘
【AI4Code】《IntelliCode Compose: Code Generation using Transformer》 ESEC/FSE 2020
vim基础操作汇总
Online Learning and Pricing with Reusable Resources: Linear Bandits with Sub-Exponential Rewards: Li
Immortal software in the computer that I don't want to delete all my life
并发编程之AQS
The migration of arm architecture to alsa lib and alsa utils is smooth
Leetcode 113. path sum II
刷题-洛谷-P1035 级数求和
Basic knowledge of binary tree
【AI4Code】《Pythia: AI-assisted Code Completion System》(KDD 2019)
Canvas judgment content is empty
【GCN-RS】Learning Explicit User Interest Boundary for Recommendation (WWW‘22)
Concurrent programming - memory model JMM









