The source code to check a hash collection is empty or not is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
# Ruby program to check a hash collection
# is empty or not
hash1 = {"101" => "Amit", "102" => "Arun", "103" => "Sumit"};
hash2 = {};
if hash1.empty?() == true
puts "hash1 collection is empty";
else
puts "hash1 collection is not empty";
end
if hash2.empty?() == true
puts "hash2 collection is empty";
else
puts "hash2 collection is not empty";
end
Output:
hash1 collection is not empty
hash2 collection is empty
Explanation:
In the above program, we created two hash collections. Then we checked created collections are empty or not using empty?() method and printed the appropriate message.
Program/Source Code:
The source code to check a hash collection is empty or not is given below. The given program is compiled and executed on Windows 10 Operating System successfully.
Output:
Explanation:
In the above program, we created two hash collections. Then we checked created collections are empty or not using empty?() method and printed the appropriate message.
need an explanation for this answer? contact us directly to get an explanation for this answer