Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

40,011 questions

51,958 answers

573 users

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 86 views
86 views asked Mar 12, 2023 by avibootz
1 answer 90 views
1 answer 115 views
2 answers 139 views
139 views asked Nov 26, 2023 by avibootz
1 answer 127 views
127 views asked Mar 12, 2023 by avibootz
...