Created
June 27, 2012 19:51
-
-
Save pcsanwald/3006377 to your computer and use it in GitHub Desktop.
collections example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.redowl.prototype; | |
import static org.junit.Assert.*; | |
import java.util.Collection; | |
import java.util.List; | |
import org.junit.Test; | |
import com.google.common.base.Predicate; | |
import com.google.common.collect.Collections2; | |
import com.google.common.collect.Lists; | |
public class GuavaWalkthrough { | |
@Test | |
public void test() { | |
// generics on the left hand side only, cool! | |
Collection<Integer> numbers = Lists.newArrayList(); | |
for (int i = 0; i < 10; i++) { | |
numbers.add(i); | |
} | |
Collection<Integer> filteredNumbers = Collections2.filter(numbers, new IsEven()); | |
System.out.println(filteredNumbers); | |
} | |
public class IsEven implements Predicate<Integer> { | |
@Override | |
public boolean apply(Integer compare) { | |
return compare % 2 == 0; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment