Ask Question
29 June, 15:42

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. 29 June, 15:57
    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?
Get 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 there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers