You can do it using a Set
. You need unique elements and Set
gurantees you containing the unique elements. HashSet
is implementation of Set
, you can use it to implement this idea.
public boolean ifAllCharsUnique(String input){
char[] arr = input.toCharArray();
int length = arr.length;
Set<Character> checker = new HashSet<>();
for(int i =0 ; i < length; i++){
if(checker.contains(arr[i]){
return false;
}
checker.add(arr[i]);
}
return true;
}
1
solved How tho check in Java if there is same characters in a String? [closed]