Skip to content

Commit 6b49159

Browse files
authored
Create UniqueNames.java
1 parent 0e5a79a commit 6b49159

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

UniqueNames.java

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package com.zetcode;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class UniqueNames {
7+
8+
public static void main(String[] args) {
9+
10+
List<String> names = List.of("Martin", "Lucy", "Peter",
11+
"Martin", "Robert", "Peter");
12+
13+
List<String> uniqueNames = new ArrayList<>();
14+
15+
names.forEach(e -> {
16+
17+
if (!uniqueNames.contains(e)) {
18+
19+
uniqueNames.add(e);
20+
}
21+
});
22+
23+
System.out.println(names);
24+
System.out.println(uniqueNames);
25+
26+
}
27+
}

0 commit comments

Comments
 (0)