Search
Winners

Win Prizes

Social Presence
Twitter Twitter LinkedIn YouTube Google

Like us on Facebook
Advertisements
Top Codes Author
Wed, 03-Sep-2014 Authors
All Time Authors
Satyapriyanayak
12160
Jayakumars
8120
Niladri.biswas
6000

Latest members | More ...


(Statistics delayed by 5 minutes)
 Codes

Find out duplicate words in a given string & remove them

Chikul
Posted by Chikul under Others on 12/10/2009 12:20:53 AM | Views : 6483 | Status : [Member]

import java.io.*;

import java.lang.*;
import java.util.*;

public class Remove_Duplicate
{
public static void main(String args[])throws IOException
{
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter a String : ");
String s=br.readLine().toString();
int i=0;
ArrayList ar=new ArrayList();

StringTokenizer st=new StringTokenizer(s," ");
while(st.hasMoreTokens())
{
ar.add(st.nextToken());

}
int l=ar.size();
String s1[]=new String[l];


Iterator itr=ar.iterator();
while(itr.hasNext())
{
s1[i]=itr.next().toString();

i++;
}

for(i=0;i<l;i++)
{
for(int j=i+1;j<l;j++)
{
if(s1[i].equalsIgnoreCase(s1[j]))
{
s1[j]="null";

}
}
}
System.out.println();
for(i=0;i<l;i++)
{
if(s1[i].equals("null"))
{

}
else
{
System.out.print(" "+s1[i]+" ");
}
}

}}


Found interesting? Add this to:



Comments or Responses


Login to post response