I have a String which I turn into an int stream of the ASCI numbers of the char values of each char of the String and then map it back to a String and also print out every char.
All of this works but I have a weird interaction with the .distinct() function that I don't quite understand.
It works just fine for my printer(c) function and the Output is:
hello d
hello c
hello b
hello a
so it doesn't print the second b but if I print out a
itself after the String still has the 2nd b.
What is the reason for that interaction?
public class MapTesting { public static void main(String [] args) {
String a = "dcbba";
a.chars().distinct().mapToObj( c -> (char) c).forEach(c -> MapTesting.printer(c));
System.out.println(a);
}
public static void printer(Character c) {
System.out.println("hello " + c);
}
}