4

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"};
2
  • Aside: In C#, the above array can be defined even more concisely as: var strArr = new [] {"ram", "sam", "kam"}; Commented Jul 26, 2010 at 19:10
  • @Rahuλ G, yeah we can do that.. :) Commented Jul 26, 2010 at 19:15

1 Answer 1

13

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
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.