Ask Question
25 March, 20:56

Write a public static method called getPIDs that has a parameter of type Map called nameToPID (keys are student names and values are student PIDs). It should return a HashSet containing all PIDs in nameToPID.

+5
Answers (1)
  1. 25 March, 21:22
    0
    Java program is explained below

    Explanation:

    import java. util. HashSet;

    import java. util. Map;

    import java. util. TreeMap;

    public class TruckRace1 {

    public static HashSet getPIDs (MapnameToPID) {

    HashSet pidSet = new HashSet ();

    for (String ids: nameToPID. values ()) {

    pidSet. add (ids);

    }

    return pidSet;

    }

    public static void main (String[] args) {

    Map pids = new TreeMap ();

    pids. put ("John","123");

    pids. put ("Jason","124");

    pids. put ("Peter","125");

    pids. put ("Alice","126");

    pids. put ("Peny","129");

    HashSet ids = getPIDs (pids);

    for (String id:ids) {

    System. out. println (id);

    }

    }

    }
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “Write a public static method called getPIDs that has a parameter of type Map called nameToPID (keys are student names and values are ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers