The source code to get value from the hash collection based on a specified key is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
# Ruby program to get value from hash collection
# based on specified key
student = {"101" => "Amit", "102" => "Arun", "103" => "Sumit"};
print "Student information: \n";
print student["101"],"\n";
print student["102"],"\n";
print student["103"],"\n";
Output:
Student information:
Amit
Arun
Sumit
Explanation:
In the above program, we created a hash collection to store student information. Then we get the student's name based on specified keys and printed them.
Program/Source Code:
The source code to get value from the hash collection based on a specified key is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
Output:
Explanation:
In the above program, we created a hash collection to store student information. Then we get the student's name based on specified keys and printed them.
need an explanation for this answer? contact us directly to get an explanation for this answer