1

How do I define an array that contains an integer and three strings with only 20 elements and fill the integer with zero?

I tried but without success:

val a = Array [(Int,String,String,String)].fill(20)(0)
1
  • How about Array.fill(20)((0,"","",""))? Commented Nov 24, 2012 at 13:14

2 Answers 2

5

The fill answers are fine, but it's worth saying here that by the time you are at a 4-tuple, your code clarity would almost certainly be improved with a case class. This is particularly true since three of your fields are strings, which is going to make it really easy to get confused as to just which field means what.

Sign up to request clarification or add additional context in comments.

Comments

4

Try something like this:-

 Array.fill(20)((0,"","",""))

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.