Logo

Programming-Idioms

History of Idiom 57 > diff from v3 to v4

Edit summary for version 4 by :

Version 3

2015-01-15, 23:37:11

Version 4

2015-01-15, 23:44:11

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering.

Idiom #57 Filter list

Create list y containing items from list x satisfying predicate p. Respect original ordering.

Code
List<T> y = new ArrayList<T>();
for (T v: x)
	if (p(v))
		y.add(v);
Comments bubble
Here p is just a method, not an object.
Origin
http://stackoverflow.com/questions/122105/what-is-the-best-way-to-filter-a-java-collection