<dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-collections4</artifactId> <version>4.4</version> </dependency> import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.collections4.PredicateUtils; import org.apache.commons.collections4.TransformerUtils; List<String> list1 = Arrays.asList("apple", "banana"); List<String> list2 = Arrays.asList("car", "dog"); List<String> mergedList = (List<String>) CollectionUtils.union(list1, list2); List<Integer> numbers = Arrays.asList(1, 2, 3, 4, 5); List<Integer> filteredList = (List<Integer>) CollectionUtils.select(numbers, PredicateUtils.notNullPredicate()); List<String> fruits = Arrays.asList("apple", "banana", "orange"); List<String> capitalizedFruits = (List<String>) CollectionUtils.collect(fruits, TransformerUtils.invokerTransformer("toUpperCase"));


上一篇:
下一篇:
切换中文