Hello,
I am having problems in bMethod. The program compiles but there is no output display for bMethod. I am trying obtain a set from aMethod and assign this set to a suitable local variable in bMethod. Which I think where the problem is. I want trying to display both duplicates (thats where I have used HashSet) and display unique names. Thanks in advance for your help.
public class ExampleClass
{
Set<String> names = new TreeSet<String>();
public ExampleClass()
{
super();
names = new TreeSet<String>();
}
public static void aMethod()
{
String[] name1 = {"Amy", "Jose", "Jeremy", "Alice", "Patrick" };
String[] name2 = { "Alan", "Amy", "Jeremy", "Helen", "Alexi" };
for (int i = 0; i < name1.length; i++)
{
names.add(name1[i]);
}
System.out.print(names);
System.out.println();
for (int i = 0; i < name2.length; i++)
{
names.add(name2[i]);
}
System.out.print(names);
System.out.println();
}
public static void bMethod()
{
Set<String> names = new HashSet<String>();
for (String a : anagramTable)
{
if
(!names.add(a))
System.out.println("Duplicate detected: " + a);
else
{
System.out.println(" " + names);
}
}