Skip to content

Instantly share code, notes, and snippets.

@csamuel
Created February 9, 2011 04:57
Show Gist options
  • Save csamuel/817904 to your computer and use it in GitHub Desktop.
Save csamuel/817904 to your computer and use it in GitHub Desktop.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class EvensFilter {
public static void main (String [] args)
{
List<Integer> listA = Arrays.asList(1,2,3,4);
List<Integer> listB = new ArrayList<Integer>();
for(Integer n : listA) {
if(n % 2 == 0) {
listB.add(n);
}
}
// Prints "[2, 4]"
System.out.println(listB);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment