Related Articles

Related Articles

Ruby | Array class empty?() operation
  • Last Updated : 08 Jan, 2020

Array#empty?() : empty?() is a Array class method which checks if the array is empty or not.

Syntax: Array.empty?()

Parameter: Array

Return: true – if no element is present in the array; otherwise false

Code #1 : Example for empty?() method



filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for empty?() method
  
# declaring array
a = [18, 22, 33, nil, 5, 6]
  
# declaring array
b = [1, 4, 1, 1, 88, 9]
  
# declaring array
c = []
  
# empty?
puts "empty? : #{a.empty?()}\n\n"
  
# empty?
puts "empty? : #{b.empty?()}\n\n"
  
# empty?
puts "empty? : #{c.empty?()}\n\n"

chevron_right


Output :

empty? : false

empty? : false

empty? : true

Code #2 : Example for empty?() method

filter_none

edit
close

play_arrow

link
brightness_4
code

# Ruby code for empty?() method
# declaring array
a = ["abc", "nil", "dog"]
  
# declaring array
b = ["cow", nil, "dog"]
  
# declaring array
c = ["cat", nil, nil]
  
# empty?
puts "empty? : #{a.empty?()}\n\n"
  
# empty?
puts "empty? : #{b.empty?()}\n\n"
  
# empty?
puts "empty? : #{c.empty?()}\n\n"

chevron_right


Output :

empty? : false

empty? : false

empty? : false



My Personal Notes arrow_drop_up
Recommended Articles
Page :