1public static void main(String[] args) {
2
3 String result = removeDup("AAABBBCCC");
4 System.out.println(result); // ABC
5
6public static String removeDup( String str) {
7 String result = "";
8 for (int i = 0; i < str.length(); i++)
9 if (!result.contains("" + str.charAt(i)))
10 result += "" + str.charAt(i);
11 return result;
12 }
13}
1String fullString = "lol lol";
2String[] words = fullString.split("\\W+");
3StringBuilder stringBuilder = new StringBuilder();
4Set<String> wordsHashSet = new HashSet<>();
5
6for (String word : words) {
7 if (wordsHashSet.contains(word.toLowerCase())) continue;
8 wordsHashSet.add(word.toLowerCase());
9 stringBuilder.append(word).append(" ");
10}
11String nonDuplicateString = stringBuilder.toString().trim();
1String str1 = "ABCDABCD";
2String result1 = "";
3
4for (int a = 0; a <= str1.length()-1; a++) {
5if (result1.contains("" + str1.charAt(a))) {
6// charAt methodda you provide index number ve sana character olarak donuyor,
7// If the string result does not contains str.CharAt(i),
8// then we concate it to the result. if it does we will not
9 continue;
10}
11result1 += str1.charAt(a);
12}
13System.out.println(result1);