ADVERTISEMENT
ADVERTISEMENT

Ruby program to get value from the hash collection based on specified key

Ruby Example: Write a program to get value from the hash collection based on specified key.
Submitted by Nidhi, on February 14, 2022

Problem Solution:

In this program, we will create a hash collection and get values from the hash collection using specified keys.

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.

# 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.

Ruby Hashes Programs »


ADVERTISEMENT
ADVERTISEMENT


Comments and Discussions!



ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.