I want to filter the list by unique elements with case insensitive filtering using java 8.
E.g: 1) Input: Goodbye bye Bye world world WorlD
Output: Goodbye bye world
2) Input: Sam went went to to To his business
Output: Sam went to his business
I tried by following code. I have used distinct() for unique elements and map(x->x.toLowerCase()) so that distinct() will filter unique elements by lowering its case.
System.out.println("Enter the no of lines u will input:: ");
Scanner sc = new Scanner(System.in);
Integer noOfLines = sc.nextInt();
sc.nextLine();
List<String> listForInput;
List<List<String>> allInputs = new ArrayList<>();
for(int i =0; i<noOfLines; i++)
{
String receivedLine = sc.nextLine();
String[] splittedInput = receivedLine.split(" ");
List<String> list = Stream.of(splittedInput)
.map(x->x.toLowerCase())
.distinct()
.collect(Collectors.toList());
list.forEach(x-> System.out.print(x+" "));
but in the output I get all the elements in lower case. Is there better I can do using java 8 or m I doing something wrong here?