public class RemoveDuplicatesFromString {
	public static void main(String[] args) {
		RemoveDuplicatesFromString rsd = new RemoveDuplicatesFromString();
		String input = "Tree Traversal";
		System.out.println(rsd.getUniqueString(input));
	}

	public String getUniqueString(String input) {
		boolean[] isUsed = new boolean[256];
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < input.length(); i++) {
			int position = input.charAt(i);
			if (!isUsed[position]) {
				sb.append(input.charAt(i));
				isUsed[position] = true;
			}
		}
		return sb.toString();
	}
}
@@ -1,12 +1,291 @@
+// Program to remove duplicates from a given string%0A// 1. getUniqueString(String) method uses a boolean array.%0A// 2. removeDuplicates(String) method uses a hash map.%0A// Both the methods have O(n) space and time complexity. (n being the string length)%0A%0Aimport java.util.HashMap;%0A%0A
 public class
@@ -481,16 +481,30 @@
 println(
+%22Method 1: %22 +
 rsd.getU
@@ -524,16 +524,81 @@
 nput));%0A
+%09%09System.out.println(%22Method 2: %22 +rsd.removeDuplicates(input));%0A
 %09%7D%0A%0A%09pub
@@ -924,9 +924,332 @@
 g();%0A%09%7D%0A
-%7D
+%09%0A%09public String removeDuplicates(String input) %7B%0A%09%09HashMap%3CCharacter, Integer%3E map = new HashMap%3C%3E();%0A%09%09StringBuffer sb = new StringBuffer(%22%22);%0A%09%09for (int i = 0; i %3C input.length(); i++) %7B%0A%09%09%09char c = input.charAt(i);%0A%09%09%09if (!map.containsKey(c)) %7B%0A%09%09%09%09sb.append(c);%0A%09%09%09%09map.put(c, 1);%0A%09%09%09%7D%0A%09%09%7D%0A%09%09return sb.toString();%0A%09%7D%0A%7D%0A

Update RemoveDuplicatesFromString.java