package collections;
import java.util.HashSet;
import java.util.Set;
public class DupsAndUniques {
public static void main(String[] args) {
Set<String> dups=new HashSet<String>();
Set<String> uniqs=new HashSet<String>();
for (String s:args)
{
if(!uniqs.add(s))
{
dups.add(s);
}
}
//To get the unique elements in unique variable
uniqs.removeAll(dups);
System.out.println("Duplicate Words: "+dups);
System.out.println("Unique Words: "+uniqs);
}
}
When we run this in eclipse we also have to give command line arguments.For this just click on run menu then select run configurations and you will get a screen where select the program and then click on arguments menu.It will look like this
import java.util.HashSet;
import java.util.Set;
public class DupsAndUniques {
public static void main(String[] args) {
Set<String> dups=new HashSet<String>();
Set<String> uniqs=new HashSet<String>();
for (String s:args)
{
if(!uniqs.add(s))
{
dups.add(s);
}
}
//To get the unique elements in unique variable
uniqs.removeAll(dups);
System.out.println("Duplicate Words: "+dups);
System.out.println("Unique Words: "+uniqs);
}
}
When we run this in eclipse we also have to give command line arguments.For this just click on run menu then select run configurations and you will get a screen where select the program and then click on arguments menu.It will look like this
0 comments:
Post a Comment