$param = k.chomp.split("\t")
How can I find the length of $param
given that it is an array? actually when I'm writing
puts $param.class
I got the o/p like Array. Now how do I find the length of this array?
I tried $param.length
but it's not working.
Basically, the length of an array is the total number of the elements which is contained by all the dimensions of that array. Property Value: This property returns the total number of elements in all the dimensions of the Array. It can also return zero if there are no elements in the array.
To get the size of a Java array, you use the length property. To get the size of an ArrayList, you use the size() method.
Java String length() Method The length() method returns the length of a specified string. Note: The length of an empty string is 0.
Ref Array class
k = "This \t is \t just \t testing" $param=k.chomp.split("\t") array_length= $param.length #or $param.size puts "length of $param is : #{array_length}"
o/p
length of $param is : 4
Try using .size
like this:
$param.size
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With