DEV Community

Mohammed Riyas
Mohammed Riyas

Posted on

java traditional method to remove duplicate String

I just saw a post in dev someone solved same problem using collections in java. so i thought let me try the same problem to solve in traditional way`

  1. public class Main
    {
    public static void main(String[] args) {
    String s="abbvcddgtttt";
    char c[]=s.toCharArray();
    char cc[]=new char[c.length];
    int index=0;
    char same=' ';
    for(int i=0;i<c.length;i++)
    {
    for(int j=i+1;j<c.length;j++)
    {
    if(c[i]==c[j])
    {
    c[i]=' ';
    }
    }
    if(c[i]!=' ')
    {
    cc[index]=c[i];
    index++;
    }

    }
    for(char i:cc)
    {
    

    System.out.println(i);
    }
    }
    }

Top comments (0)