Java Program To Find First NonRepeated Character
Java Program To Find First NonRepeated Character
Non-Repeated Character In
String
First we will split string based on “” empty string value
and will store into Array of string and after that we will
use Arrays.Stream(-) method and convert into stream
and after converting into stream we can
call .collect(-) method.Inside collect(-) method we can
pass the parameter Collectors.groupingBy(-,-) and
Inside Collectors.groupingBy(-,-) function we can pass
the two parameters one is Function.identity() to find the
unique identity of each element and second parameter we
can paas Collectors.counting() to count the number of
occurrence for each character. After that we again need to
convert Map into stream to apply stream functions. So we
can call .entrySet().stream() and now we can apply the
filter and restrict the data based on condition .filter(ele -
> ele.getValue() == 1) . Now we will store all the non
repeated keys into ArrayList and will pick the first non
repeated character and Print the output.
package com.demo.main;
import java.util.Arrays;
import java.util.LinkedHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;