mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-05-03 19:58:23 +07:00
22 lines
564 B
Java
22 lines
564 B
Java
// "Replace with forEach" "false"
|
|
import java.util.*;
|
|
|
|
class A {
|
|
public static void main(String[] args) {
|
|
List<String> names = Arrays.asList("Bob", "Alice", "Bob", "Carol");
|
|
Set<String> uniqNames = new HashSet<>(names.size());
|
|
for (String name : na<caret>mes){
|
|
uniqNames.add(makeNameUnique(name, uniqNames));
|
|
}
|
|
uniqNames.forEach(System.out::println);
|
|
}
|
|
|
|
private static String makeNameUnique(final String name, final Set<String> uniqNames) {
|
|
if (uniqNames.contains(name)) {
|
|
return name + "1";
|
|
}
|
|
return name;
|
|
}
|
|
|
|
|
|
} |