Ask Question
Today, 18:53

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.

+3
Answers (1)
  1. Today, 22:14
    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 and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers