Created
May 1, 2015 15:57
-
-
Save yusufsyaifudin/9bd867e413a2a531f53c to your computer and use it in GitHub Desktop.
Return set of unique character from given string
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
String s = "hksaksaggah";//sample string | |
String temp2="";//string with no duplicates | |
HashMap<Integer, Character> tc = new HashMap<>();//create a hashmap to store the char's | |
char [] charArray = s.toCharArray(); | |
for (Character c : charArray)//for each char | |
{ | |
if (!tc.containsValue(c))//if the char is not already in the hashmap | |
{ | |
temp2=temp2+c.toString();//add the char to the output string | |
tc.put(c.hashCode(),c);//and add the char to the hashmap | |
} | |
} | |
System.out.println(temp2);//final string |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment