I have a string array as below.
String [] exmp = {"Example ExamPle", "Example"};
I want to get distinct element from the above array irrespective of character case.
I need to get the below output for above array. "Example"
I have tried with the following code.
LinkedHashSet<String> set = new LinkedHashSet<String>();
String [] exmp = {"Example ExamPle", "Example"};
for(String s : exmp) {
String unqWrds = Arrays.stream(s.split("\\s+")).distinct().collect(Collectors.joining(" "));
set.add(unqWrds);
}
But currently I am getting entire string getting added to set due to case difference "Example ExamPle", "Example"
Could you please advise here.
{"Example", "ExamPle", "Example"}, there would be one distinct value when you ignore case.