import java.util.*;
//class RemoveDuplicateCharatcersFromString = Main9
class Main9
{
public static String removeDuplicates(String s) {
StringBuilder build = new StringBuilder();
for (int i = 0; i < s.length(); i++) {
String st = s.substring(i, i + 1);
if (build.indexOf(st) == -1) {
build.append(st);
}
}
return build.toString();
}
public static void main(String[] args)
{
String str="AAA BBB ";
String newString=removeDuplicates(str);
System.out.println(newString);
}
}
out put:-
A B
Subscribe to:
Post Comments (Atom)
What is Map Collection?
A map collection refers to a set of maps that are compiled and organized for a specific purpose, such as research, education, or preservatio...
-
1) String is immutable while StringBuffer and StringBuilder is mutable object. 2) StringBuffer is synchronized while StringBuilder i...
-
#1 business planning solution LivePlan makes it easy to create a professional business plan that will wow any audience. ...
-
# include <stdio.h> # include <conio.h> void main() { long n, a[10], i, c = 0 ; clrscr() ; printf("Enter a number : ...
this question asking for me interview.......
ReplyDelete