-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathq19.java
More file actions
34 lines (29 loc) · 746 Bytes
/
q19.java
File metadata and controls
34 lines (29 loc) · 746 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package function_questions;
import java.util.*;
public class q19 {
public static void main(String[] args) {
int[] arr= {1,2,2,3,3,4,5,5,6,7};
System.out.println("After removing duplicates Elements");
removeduplicatesElements(arr);
System.out.println("\nDuplicates elements Are");
duplicateElements(arr);
}
private static void duplicateElements(int[] arr) {
Set<Integer> s1=new HashSet<>();
for(int n1: arr) {
boolean ans=s1.add(n1);
if(ans==false) {
System.out.print(n1+",");
}
}
}
private static void removeduplicatesElements(int[] arr) {
Set<Integer> s1=new HashSet<>();
for(int n1: arr) {
s1.add(n1);
}
for(int n2: s1) {
System.out.print(n2+",");
}
}
}