Skip to content

Instantly share code, notes, and snippets.

@zvozin
Created July 11, 2010 19:12
Show Gist options
  • Save zvozin/471752 to your computer and use it in GitHub Desktop.
Save zvozin/471752 to your computer and use it in GitHub Desktop.
public static <T> Collection<T> toStringFiltered(List<T> aListOfTs) {
return Collections2.filter(aListOfTs, new Predicate<T>()
{
public boolean apply(T from) {
return from.toString().isEmpty();
}
});
}
<dependency>
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
<version>1.0</version>
</dependency>
public static <T> Collection<String> toString(List<T> aListOfTs) {
return Collections2.transform(aListOfTs, new Function<T, String>()
{
public String apply(T from) {
return from.toString();
}
});
}
public static <T> List<String> toString(List<T> aListOfTs) {
List<String> toPrint = new ArrayList<String>();
for (T aT : aListOfTs) {
toPrint.add(aT.toString());
}
return toPrint;
}
aListOfTs.map(_.toString)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment