Skip to content

Instantly share code, notes, and snippets.

@hanaori
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hanaori/6ca661a977e53885f7d8 to your computer and use it in GitHub Desktop.
Save hanaori/6ca661a977e53885f7d8 to your computer and use it in GitHub Desktop.
Check the String whether it has the same character.
public boolean isUnique(String str) {
boolean isUnique = true;
HashSet<Character> hs = new HashSet<>();
for(char c: str.toCharArray()){
if(!hs.contains(c)){
hs.add(c);
}else{
isUnique = false;
break;
}
}
return isUnique;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment