I have a helpful function that searches for indexed duplicate letters in the string. Now what is the best way to remove these duplicates? Thanks!
This is the best way to me. It takes a string, it separates it into characters, puts it in the hashase (non-compiler, is ordered) and then prints (or can return the string.
< Strong> This is the best way out of the list of people
string example = "this code"; four [] character = example.CalcarArray (); Set & lt; character & Gt; str = New Linked Hesheat & lt; Character & gt; (); for (four C: Characters) {str.add (c);} StringBeilder SB = New stringbilder (); for (character character: str) {sb.append (character);} System.out.println (sb.toString ()); Public Static String Convert (String Example) {char [] chars = example.toCharArray (); Set & lt; Character & gt; str = new LinkedHashSet & lt; Character & gt; (for); (Four C: Characters) } {Str.add (c);} stringbilder sb = new stringbilder (); for (character character: str) {sb.append (character);} return sb.toString ();}
Another way to do this:
string example = "to it D "; Stringbilder sb = new string builder (example); Repeat through (int i = 0; i & lt; example.length (); i ++) // characters if included in (! Sb.toString (.) (Example.charAt (i) + "")) // Define whether its stringbillers are in sb.append (e.g., Chart (i)); // If it does not add the example = sb.toString (); // results take system.out.println (example);
Disabled, but easy implementation
string example = "this code"; String empty = ""; Boolean alphabet [] = new boolean [26]; For (four C: for example: Carrera ()) if (Alphabet [(int) ((C + ""). TLover Seas (). Charite (0) - 'A']] == False + = C; Example = empty; Println (example);
Hope it helps.
No comments:
Post a Comment