Test your technical skills online, appear in Virtual Interview and be ready for job!
Twitter Twitter LinkedIn YouTube Google
Be Interview ready ! | Search
Make friends on DotNetFunda.com and expand your network!
Winners

Win Prizes

Announcements
Like us on Facebook
Sponsor
Top Codes Author
Wed, 23-Apr-2014 Authors
Zondray
40
All Time Authors
Satyapriyanayak
11600
Jayakumars
8120
Niladri.biswas
6000

Latest members | More ...


(Statistics delayed by 5 minutes)

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 : 5657 | 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.

Comments / Responses
Select text & click toolbar to format. Formatting appears in viewmode only. HTML Tags are not allowed.
Bold Italic Underline Paragraph Title Code  Link 
 Wait ... Processing ..... please wait.