NOTE: The question has been heavily edited, to the point that it is now a completely different question. This answer is for the original question. The edited question makes no sense to me at this point, so I have not modified this answer to address the edited version.
This should do it:
public static List<Integer> lessThanZero(List<Integer> list) {
List<Integer> result = new ArrayList<>();
for (Integer val : list) {
if (val < 0) {
result.add(val);
}
}
return result;
}
Or, as of Java 8, you can do it with streams:
public static List<Integer> lessThanZero(List<Integer> list) {
return list.stream().filter(v -> v < 0).collect(Collectors.toList());
}