Skip to content

Commit caa9a8b

Browse files
authored
Added a new program "ArrayListDuplicates"
Code is written on Java with the help of ArrayList
1 parent d4f6b3d commit caa9a8b

1 file changed

Lines changed: 29 additions & 0 deletions

File tree

ArrayListDuplicateApp.java

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// https://www.facebook.com/smkmallik/posts/3415890411793806
2+
// Subscribed by Code House
3+
import java.util.ArrayList;
4+
import java.util.LinkedHashSet;
5+
import java.util.List;
6+
import java.util.Set
7+
8+
class ArrayListDuplicateApp {
9+
public static void main(String[] args) {
10+
List<Integer> primes = new ArrayList<Integer>();
11+
12+
primes.add(2);
13+
primes.add(3);
14+
primes.add(5);
15+
primes.add(7);
16+
primes.add(7);
17+
primes.add(11);
18+
19+
System.out.println("List of Prime Numbers: " + primes);
20+
21+
Set<Integer> primesWithoutDuplicates = new LinkedHashSet<Integer>(primes);
22+
23+
primes.clear();
24+
25+
primes.addAll(primesWithoutDuplicates);
26+
27+
System.out.println("List of primes without duplicates: " + primes);
28+
}
29+
}

0 commit comments

Comments
 (0)