Merge two arrays into one
June 28, 2012
Check if two strings are anagrams
July 3, 2012

Remove duplicates from a string

Java Code

Thanks Arun Tomar for providing the code.

Below is the solution with Java Collection perspective. Please see to it if it fine according to the best case solutions.

    public class Ritamtest
    {
        private static String name = "social.ritambhara.in";
        public static void main(String[] arun) {
            removeDuplicate(name);
        }
        private static void removeDuplicate(String str) {
            Set<Character> set = new TreeSet<Character>();
            for (int i = 0; i < str.length(); i++) {
                if (!(set.contains(str.charAt(i)))) {
                    set.add(str.charAt(i));
                }
            }
            for (char cha : set) {
                System.out.println("Set values : " + cha);
            }
        }
    }

Please let me know your feedback / suggestions / comments.

2 Comments

  1. anonymous says:

    where is n in array?

Leave a Reply

Your email address will not be published. Required fields are marked *