org.apache.commons.collections4.CollectionUtils.filter() usuli -
public static boolean filter(Iterablecollection,
Predicate super T> predicate)
Parametrlar yig'ish - kirishni olish uchun to'plam null bo'lmasligi mumkin.
predikat - filtr sifatida ishlatiladigan predikat null bo'lishi mumkin.
Qaytish qiymati Agar to'plam ushbu chaqiruv orqali o'zgartirilsa, rost, aks holda noto'g'ri.
Misol org.apache.commons.collections4.CollectionUtils.filter() usulidan foydalanishni ko'rsatadi . Biz faqat juft raqamlarni olish uchun butun sonlar ro'yxatini filtrlaymiz.
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.collections4.Predicate;
public class CollectionUtilsTester {
public static void main(String[] args) {
List integerList = new ArrayList();
integerList.addAll(Arrays.asList(1,2,3,4,5,6,7,8));
System.out.println("Original List: " + integerList);
CollectionUtils.filter(integerList, new Predicate() {
@Override
public boolean evaluate(Integer input) {
if(input.intValue() % 2 == 0) {
return true;
}
return false;
} });
System.out.println("Filtered List (Even numbers): " + integerList);
}}
Natija: Original List: [1, 2, 3, 4, 5, 6, 7, 8]
Filtered List (Even numbers): [2, 4, 6, 8]
filterInverse() usuli CollectionUtils ning filterInverse() usuli o'tkazilgan predikat tomonidan taqdim etilgan shartni qondiradigan ob'ektlarni olib tashlash uchun ro'yxatni filtrlash uchun ishlatilishi mumkin.
Deklaratsiya org.apache.commons.collections4.CollectionUtils.filterInverse() usuli −
public static boolean filterInverse(Iterable collection, Predicate super T> predicate)
Parametrlar yig'ish - kirishni olish uchun to'plam null bo'lmasligi mumkin.
predikat - filtr sifatida ishlatiladigan predikat null bo'lishi mumkin.
Qaytish qiymati Agar to'plam ushbu chaqiruv orqali o'zgartirilsa, rost, aks holda noto'g'ri.