Skip to content

Commit 36991e0

Browse files
remove duplicate characters from String
remove duplicate characters from String? (solution) This is one of the interesting String question, which also has lots of variants. You need to remove duplicate characters from a given string keeping only the first occurrences. For example, if the input is ‘bananas’ the output will be ‘bans’. Pay attention to what output could be, because if you look closely original order of characters are retained the in output. This is where many developer make the a mistake of shorting character array of String and removing duplicates, similar to how you remove duplicates from array. That destroys original order of characters and will not be correct solution in this case.
1 parent 86881e5 commit 36991e0

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

Challenge14.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import static org.junit.Assert.assertTrue;
44

5+
56
import java.util.LinkedHashSet;
67
import java.util.Set;
78
import org.junit.jupiter.api.Test;
@@ -10,8 +11,8 @@
1011
* The Class Challenge14. remove duplicate characters from String? This is one
1112
* of the interesting String question, which also has lots of variants. You need
1213
* to remove duplicate characters from a given string keeping only the first
13-
* occurrences. For example, if the input is ‘bananas’ the output will be
14-
* ‘bans’. Pay attention to what output could be, because if you look closely
14+
* occurrences. For example, if the input is ‘bananas’ the output will be
15+
* ‘bans’. Pay attention to what output could be, because if you look closely
1516
* original order of characters are retained the in output
1617
*
1718
*/

0 commit comments

Comments
 (0)