Both implementations are incorrect as they needlessly mutate the input list:
List<String> namesNotStartingWithB = new ArrayList<>();
for (String name : names) {
if (!name.startsWith("B")) {
namesNotStartingWithB.add(name);
}
}
Imagine a scenario where you're filtering one of the arguments to a method: the input will be mutated with no indication to the caller (or in the method signature), causing bugs, iterator invalidation etc.