List list1 = Arrays.asList("apple","hina","banana","didi","didi"); List list2 = Arrays.asList("singh","hina","banana","didi","didi"); List collect = Stream.concat(list1.stream(),list2.stream()).distinct().collect(Collectors.toList()); System.out.println(collect);
Q No: 18:Given two lists of strings, concatenate them and remove duplicates using stream API.
Code:
=====
List list1 = List.of("apple", "banana", "orange", "pinaaple");
List list2 = List.of("banana", "kiwi", "grape", "guava", "apple");
Stream.concat(list1.stream(), list2.stream()).
distinct().
forEach(System.out::println);
List list1 = Arrays.asList("apple","hina","banana","didi","didi");
List list2 = Arrays.asList("singh","hina","banana","didi","didi");
List collect = Stream.concat(list1.stream(),list2.stream()).distinct().collect(Collectors.toList());
System.out.println(collect);