Remove Duplicate Character from a given String or find Unique alphabet in a given string

Remove Duplicate Character from a given String or find Unique alphabet in a given string
SOURCE : DuplicateCharacterRemove.java

import java.util.HashSet;

public class DuplicateCharacterRemove {

/**
* @param args
*/
public static void main(String[] args){
String s = "AABBCCDBBEEFF";
HashSet hset = new HashSet();
for(Character c : s.toCharArray()){

if (!(hset.contains(c))){
hset.add(c);
}


}
System.out.println(hset);
}
}





INPUT

String s = "AABBCCDBBEEFF";



OUTPUT

[A, B, C, D, E, F]






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment