-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsample3.java
More file actions
57 lines (55 loc) · 1.42 KB
/
sample3.java
File metadata and controls
57 lines (55 loc) · 1.42 KB
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.util.ArrayList;
import java.util.Collections;
public class sample3 {
public static ArrayList duplicate(ArrayList bl)
{
ArrayList cl=new ArrayList<>();
cl.clear();
for(int i=0;i<bl.size();i++)
{
Object o=bl.get(i);
if(o instanceof Integer)
{
Integer n=(Integer)o;
if(Collections.frequency(bl,n)>1 && !cl.contains(n) )
{
cl.add(n);
}
}
}
System.out.println(" Duplicates are:");
return cl;
}
public static ArrayList removeduplicate(ArrayList bl)
{
ArrayList cl=new ArrayList<>();
cl.clear();
for(int i=0;i<bl.size();i++)
{
Object o=bl.get(i);
if(o instanceof Integer)
{
Integer n=(Integer)o;
if(Collections.frequency(bl,n)==1 )
{
cl.add(n);
}
}
}
System.out.println("non Duplicates are:");
return cl;
}
public static void main(String[] args)
{
ArrayList al=new ArrayList<>();
al.add(100);
al.add(67);
al.add(100);
al.add(67);
al.add(4);
ArrayList dl=removeduplicate(al);
ArrayList el=duplicate(al);
System.out.println(dl);
System.out.println(el);
}
}