How to join two collections with filter in Java

1 Answer

0 votes
import java.util.Arrays;
import java.util.Collection;
import java.util.stream.Stream;
import java.util.stream.Collectors;
 
public class MyClass {
    public static void main(String args[]) {
        Collection<String> co1 = Arrays.asList("java", "c", "c++", "rust");
        Collection<String> co2 = Arrays.asList("python", "php", "c#");
     
        Collection<String> result = Stream.concat(
                        co1.stream(), co2.stream())
                        .filter(el -> el.length() > 3)
                        .collect(Collectors.toList());

        System.out.println(result);
    }
}
 
 
 
 
/*
run:
 
[java, rust, python]
 
*/

 



answered Mar 12, 2023 by avibootz

Related questions

1 answer 108 views
108 views asked Mar 12, 2023 by avibootz
1 answer 108 views
1 answer 138 views
2 answers 187 views
187 views asked Nov 26, 2023 by avibootz
1 answer 174 views
174 views asked Mar 12, 2023 by avibootz
...