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...
-
Sure, here is an example program in Java that swaps two characters in a string: public class StringSwapExample { public static void main...
-
import java.util.*; //class RemoveDuplicateCharatcersFromString = Main9 class Main9 { public static String removeDuplicates(String s) {...
-
// * execute without main method Program *// class Maind { static { System.out.println("Hello execute without main method."); ...
this question asking for me interview.......
ReplyDelete