Improvement article - "Check if a String Has All Unique Characters in Java"
This commit is contained in:
parthiv39731 2023-08-01 15:22:01 +05:30 committed by GitHub
parent b35f655796
commit 8f344ca0f7
1 changed files with 4 additions and 2 deletions

View File

@ -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) {