I just started playing in scala. I got a method that accepts string array as input
def Lambdatest(args:Array[String]) = args.foreach(arg=>println(arg))
And i have create a string array like this
var arr=new Array[String](3)
arr(0)="ram"
arr(1)="sam"
arr(2)="kam"
When i call Lambdatest(arr), it throws an error like the below
scala> LambdaTest(arr)
<console>:7: error: not found: value LambdaTest
LambdaTest(arr)
^
Whats the reason??
And is there a simple way to initialize the string arrays like the one in c#??
var strArr = new string[3] {"ram","sam","kam"};
Your method definition and the invocation are not the same, you define Lambdatest
yet invoke LambdaTest
.
Additionally, you can define the array as:
val arr = Array("ram", "sam", "kam")
Your code will execute, providing you correct the method invocation:
scala> Lambdatest(arr)
ram
sam
kam
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