當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


Scala Array ==()用法及代碼示例


Array#==() 是一個 Array 類方法,用於執行兩個數組之間的比較。它檢查兩個數組是否相等。

用法:Array.==()

參數:用於比較的數組

Return: true :如果數組相等
false:如果數組不相等

示例#1:


# Ruby code for ==() method 
# checking equality 
   
# differencing arrays 
a = [18, 22, 33, 4, 5, 6] 
   
# differencing arrays 
b = [18, 22, 33, 4, 5, 6] 
   
# differencing arrays 
c = [18, 22, 33, 40, 50, 6] 
   
# checking array equality 
puts "comparison : #{a == b}\n\n"
   
# checking array equality 
puts "comparison : #{a == c}\n\n"
   
# checking array equality 
puts "comparison : #{b == c}\n\n"

輸出:

comparison : true

comparison : false

comparison : false

示例#2:


# Ruby code for ==() method 
# checking equality 
   
# differencing arrays 
a = ["abc", "xyz", "dog"] 
   
# differencing arrays 
b = ["cat", "cat", "dog"] 
   
# differencing arrays 
c = ["cat", "cat", "dog"] 
   
# checking array equality 
puts "comparison : #{a == b}\n\n"
   
# checking array equality 
puts "comparison : #{a == c}\n\n"
   
# checking array equality 
puts "comparison : #{b == c}\n\n"

輸出:

comparison : false

comparison : false

comparison : true


相關用法


注:本文由純淨天空篩選整理自mayank5326大神的英文原創作品 Ruby | Array ==() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。