-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRemoveDuplicate.java
More file actions
51 lines (34 loc) · 975 Bytes
/
RemoveDuplicate.java
File metadata and controls
51 lines (34 loc) · 975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import java.util.Hashtable;
import java.util.Map.Entry;
class RemoveDuplicate
{
public static void removeDuplicate(String str){
str = str.toLowerCase();
str = str.replaceAll("\\s","");
char[] array = str.toCharArray();
System.out.println(String.valueOf(array));
Hashtable<Character,Integer> hst = new Hashtable<Character,Integer>();
char[] arr = new char[array.length];
int j = 0;
for(int i = 0 ; i < array.length ; i++){
if(hst.isEmpty()){
hst.put(array[i],1);
arr[j] = array[i];
j++;
}else if(hst.containsKey(array[i])){
System.out.println("Yes " + array[i]);
hst.put(array[i],hst.get(array[i]) + 1);
}else{
hst.put(array[i] , 1);
arr[j] = array[i];
j++;
}
}
System.out.println(String.valueOf(arr));
}
public static void main(String[] args)
{
String str = "vishal Singh";
removeDuplicate(str);
}
}