Ans :- these are the difference  between String Buffer and String Builder s.No String Buffer String Builder 1. StringBuffer is Synchronized StringBuilder is non Synchronized 2. StringBuffer  is thread safe StringBuilder is not thread safe 3 StringBuffer is less efficient …

What is the difference between StringBuffer and Stringbuilder ? Read more »

Ans:-  flatMap()  :- flatMap()  transform each element and flattern the resulting collection into a single combined collection. Example of flatMap():- package v1;import java.util.ArrayList; import java.util.Arrays; import java.util.List;import java.util.stream.Collectors; public class FlatMapExample {public static void main(String[] args) { List<List<Integer>> list=new ArrayList<>(); …

What is flatMap() ? Write code for flatMap. Read more »

Solution :- we will use Map to find Count of element using stream package p2; import java.util.Arrays; import java.util.List; import java.util.Map; import java.util.stream.Collectors; public class CountOfElement { public static void main(String[] args) { List<Integer> list=Arrays.asList(1,1,2,3,3,5,5,7,8,9,9); Map<Integer,Long> map=list.stream().collect(Collectors.groupingBy(i->i,Collectors.counting())); System.out.println(map); map=map.entrySet().stream().filter(e->e.getValue()>1).collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue)); …

How to find Count of element using stream? Read more »