Method 1:
public static void Removemethod (String s) {
StringBuffer sb=new StringBuffer ();
int Len=s.length ();
int i=0;
Boolean flag=false;
for (i=0; i<len;i++) {
Char C=s.charat (i);
if (S.indexof (c)!=s.lastindexof (c)) {
Flag=false;
}else{
Flag=true;
}
if (I==s.indexof (c))
Flag=true;
if (flag) {
Sb.append (c);
}
}
System.out.print (Sb.tostring ());
}
Results: 0123456789
Method 2:treeset
//1. Add a string loop to the TreeSet
String str= "01211113477440000447756677899123";
Treeset<string> ts=new treeset<> ();
int Len=str.length ();
for (int i=0;i<len;i++) {
Ts.add (Str.charat (i) + "");
}
2. Loop Traversal TreeSet
Iterator<string> I=ts.iterator ();
StringBuilder sb=new StringBuilder ();
while (I.hasnext ()) {
Sb.append (I.next ());
}
3. Output results
System.out.println (Sb.tostring ());//0123456789
Note: Set description
Collection set interface of a sub-interface
Set description
A set is a collection that contains no duplicate elements, that is, any two elements E1 and E2 have E1.equals (E2) =false,set have a maximum of one null element. The constructor of the set has a constraint, and the Passed-in collection parameter cannot contain duplicate elements.
HashSet of SET interface
This class implements the set interface, supported by a hash table (which is actually a HashMap instance). It does not guarantee the iteration order of the set, especially it does not guarantee that the order is immutable. This class allows null elements to be used.
HashSet Simple to use
public static void Main (string[] args) {
Hashset<string> hs=new hashset<string> ();
Hs.add ("AAAA");
Hs.add ("AAAA");
Hs.add ("bbbb");
Hs.add ("bbbb");
Hs.add ("CCCC");
Hs.add ("CCCC");
Hs.add ("dddd");
Hs.add (NULL);
Iterator<string> I=hs.iterator ();
while (I.hasnext ()) {
System.out.println (I.next ());
}
}
Output
Null
bbbb
dddd
Aaaa
Cccc
TreeSet of SET interface
This class implements the set interface, which is implemented by a two-fork tree, and the data in the TreeSet is automatically sorted and is not allowed to be placed in null values.
TreeSet Simple to use
Treeset<string> ts=new treeset<string> ();
Ts.add ("AAAA");
Ts.add ("AAAA");
Ts.add ("bbbb");
Ts.add ("bbbb");
Ts.add ("CCCC");
Ts.add ("dddd");
Ts.add ("dddd");
Iterator<string> I=ts.iterator ();
while (I.hasnext ()) {
System.out.println (I.next ());
}
Output
Aaaa
bbbb
Cccc
dddd