Hello,
In the instructions I have been asked to "declare a interface type to hold a map with sets of characters as its keys, and with sorted sets of strings as values". All this time I have been using TreeSets. Now I am not sure, I am now thinking of using TreeMap. Code below is demo TreeMap I have used. Firstly is it acceptable to use TreeSet instead of TreeMap as per instruction above. Secondly I am getting an error "non-static variable names cannot be referenced from a static context", when using TreeMap for methodB()? Thanks.
public class MyMates
{
private TreeMap names = new TreeMap();
private static String[] name1 = null;
private static String[] name2 = null;
private static String[] name3 = null;
public MyMates()
{
super();
names = new TreeMap();
}
public static void methodASet()
{
String[] name1 = new String[] {"Amy", "Jose", "Jeremy", "Alice", "Patrick"};
String[] name2 = new String[] { "Alan", "Amy", "Jeremy", "Helen", "Alexi"};
String[] name3 = new String[] { "Adel", "Aaron", "Amy", "James", "Alice" };
}
public static String methodB(String aTemp)
{
for (int i = 0; i < name1.length; i++)
{
names.add(name1[i]);
}
System.out.println(names);
for (int i = 0; i < name2.length; i++)
{
names.add(name2[i]);
}
System.out.println(names);
for (int i = 0; i < name3.length; i++)
{
names.add(name3[i]);
}
System.out.println(names);
return aTemp
}
public static void populateTable()
{
girlFriends myList = new girlFriends();
names.addAll(myList.getNames()); // same error here
}