Java program to print first non repeating character in a string
import java.util.LinkedHashMap;
public class Pracs {
public static void main(String[] args) {
String str = "";
LinkedHashMap<Character,Integer> map = new LinkedHashMap<>(26);
for(int i=0;i<str.length();i++){
char key = str.charAt(i);
Integer val = map.get(key);
if(val==null){
map.put(key,1);
}
else{
map.put(key,val+1);
}
}
map.entrySet()
.stream()
.filter(entryObj->entryObj.getValue()==1)
.findFirst()
.ifPresent(entryObj->System.out.print(entryObj.getKey()));
}
}
PLEASE WATCH BELOW VIDEO FOR FULL EXPLAINATION
public class Pracs {
public static void main(String[] args) {
String str = "";
LinkedHashMap<Character,Integer> map = new LinkedHashMap<>(26);
for(int i=0;i<str.length();i++){
char key = str.charAt(i);
Integer val = map.get(key);
if(val==null){
map.put(key,1);
}
else{
map.put(key,val+1);
}
}
map.entrySet()
.stream()
.filter(entryObj->entryObj.getValue()==1)
.findFirst()
.ifPresent(entryObj->System.out.print(entryObj.getKey()));
}
}
PLEASE WATCH BELOW VIDEO FOR FULL EXPLAINATION
Comments
Post a Comment