BAEL-6841 (#14502)
Improvement article - "Check if a String Has All Unique Characters in Java"
This commit is contained in:
parent
b35f655796
commit
8f344ca0f7
|
@ -34,9 +34,11 @@ public class UniqueCharChecker {
|
|||
char[] chars = str.toUpperCase().toCharArray();
|
||||
Set <Character> set = new HashSet <>();
|
||||
for (char c: chars) {
|
||||
set.add(c);
|
||||
if (!set.add(c)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return set.size() == str.length();
|
||||
return true;
|
||||
}
|
||||
|
||||
public static boolean useStreamCheck(String str) {
|
||||
|
|
Loading…
Reference in New Issue