Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find the length of an array class?

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

like image 434
Milan Avatar asked Jul 06 '10 07:07

Milan


People also ask

What is the length of an array?

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.

How do you find the length of an array in Java?

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.

What is length () in Java?

Java String length() Method The length() method returns the length of a specified string. Note: The length of an empty string is 0.


2 Answers

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 
like image 141
Salil Avatar answered Sep 21 '22 06:09

Salil


Try using .size like this:

$param.size 
like image 40
bradgonesurfing Avatar answered Sep 19 '22 06:09

bradgonesurfing