String str1 = "ABCDABCD";
String result1 = "";
for (int a = 0; a <= str1.length()-1; a++) {
if (result1.contains("" + str1.charAt(a))) {
// charAt methodda you provide index number ve sana character olarak donuyor,
// If the string result does not contains str.CharAt(i),
// then we concate it to the result. if it does we will not
continue;
}
result1 += str1.charAt(a);
}
System.out.println(result1);
// Java program to create a unique string
import java.util.*;
class IndexOf {
// Function to make the string unique
public static String unique(String s)
{
String str = new String();
int len = s.length();
// loop to traverse the string and
// check for repeating chars using
// IndexOf() method in Java
for (int i = 0; i < len; i++)
{
// character at i'th index of s
char c = s.charAt(i);
// if c is present in str, it returns
// the index of c, else it returns -1
if (str.indexOf(c) < 0)
{
// adding c to str if -1 is returned
str += c;
}
}
return str;
}
// Driver code
public static void main(String[] args)
{
// Input string with repeating chars
String s = "geeksforgeeks";
System.out.println(unique(s));
}
}
int i,j;
StringBuffer str=new StringBuffer();
Scanner in = new Scanner(System.in);
System.out.print("Enter string: ");
str.append(in.nextLine());
for (i=0;i<str.length()-1;i++){
for (j=i+1;j<str.length();j++){
if (str.charAt(i)==str.charAt(j))
str.deleteCharAt(j);
}
}
System.out.println("Removed non-unique symbols: " + str);