Back to project page Locast-Core-Android.
The source code is released under:
GNU General Public License
If you think the Android project Locast-Core-Android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
package com.stackoverflow; // w w w .j a va 2 s . c o m import java.util.ArrayList; import java.util.Collection; /** * License: http://creativecommons.org/licenses/by-sa/2.5/ * * @author jon + Alan * @see http://stackoverflow.com/questions/122105/java-what-is-the-best-way-to-filter-a-collection */ public class CollectionUtils { public static <T> Collection<T> filter(Collection<T> target, Predicate<T> predicate) { final Collection<T> result = new ArrayList<T>(); for (final T element: target) { if (predicate.apply(element)) { result.add(element); } } return result; } public static <T> void filterInPlace(Collection<T> target, Predicate<T> predicate) { final ArrayList<T> removeList = new ArrayList<T>(); for (final T element: target) { if (!predicate.apply(element)) { removeList.add(element); } } for (final T element: removeList){ target.remove(element); } } }