Hi you are doing amazing job thank you for that, but this was complex solution we can try this approach if you want public static void main(String[] args) { String str = "Hello World"; Set set = new HashSet(); Set set2 = new HashSet(); Character first = str.chars().mapToObj(o -> (char) o) .filter(c -> !set.add(c)).findFirst().get(); System.out.println("First Repeating char "+first); Character firstNonRepeatingChar = str.chars().mapToObj(o -> (char) o) .filter(c -> set2.add(c)).findFirst().get(); System.out.println("First nonRepeating char "+firstNonRepeatingChar); }
getting correct output 'e' is first repetitive character .... Optional firstRepeatChar = charCount.entrySet().stream().filter((e->e.getValue()>1)).map(e->e.getKey()).findFirst(); System.out.println("first repeat char: "+firstRepeatChar.orElse(null)); // e= first repeated character
Hi you are doing amazing job thank you for that, but this was complex solution we can try this approach if you want
public static void main(String[] args) {
String str = "Hello World";
Set set = new HashSet();
Set set2 = new HashSet();
Character first = str.chars().mapToObj(o -> (char) o)
.filter(c -> !set.add(c)).findFirst().get();
System.out.println("First Repeating char "+first);
Character firstNonRepeatingChar = str.chars().mapToObj(o -> (char) o)
.filter(c -> set2.add(c)).findFirst().get();
System.out.println("First nonRepeating char "+firstNonRepeatingChar);
}
If u would have explained the code that will be very helpful, you are just writing the code
Confusing code 😞.
String input = "Hello Welcome"; can you try the input for above program its giving first repeated character coming wrong
getting correct output 'e' is first repetitive character .... Optional firstRepeatChar = charCount.entrySet().stream().filter((e->e.getValue()>1)).map(e->e.getKey()).findFirst();
System.out.println("first repeat char: "+firstRepeatChar.orElse(null)); // e= first repeated character
bro If had exam can I drop a message for you
no