i am currently making this code and it suppose to output the name of someone that a list of people didn't write his/her name. i just would like to ask how can i make the output like this using Map
Output: {Andrew}
Explanation : Jay wrote Susan , Susan wrote Jay, Andrew wrote Anna, Anna wrote Jay but nobody wrote Andrew.
Thanks!
public class Main {
public static void main(String[] args) {
Main func = new Main();
System.out.println(func.test("Jay:Susan,Susan:Jay,Andrew:Anna,Anna:Jay"));
}
public PriorityQueue test(String c) {
Map < String, String > hmap = new HashMap < > ();
PriorityQueue a = new PriorityQueue();
String b = c.replaceAll("[,]", "-");
System.out.println(b);
String[] d = b.split("-");
for (int i = 0; i < d.length; i++) {
String names = d[i];
String[] temp;
String splitter = ":";
temp = names.split(splitter);
String aName = temp[0];
String cName = temp[1];
hmap.put(aName, cName);
}
System.out.println(hmap);
return a;
}
}