0

I want to definite a function like createString:

def createString(n: Int): String = {
    // do something here
    result = "?, ?, ?, ?, ?, ?, ? " // thera are n "? " in result
    result
}

As I know, ["? "]*n is the easy way in Python. But I don't know how to do it with Scala. What shoule I do?

J.Doe
  • 29
  • 1
  • 6

1 Answers1

5

I think you can find your answer here

scala> List.fill(10)("? ") # Similar to ["? "] * n in Python                                                                                          
res0: List[String] = List("? ", "? ", "? ", "? ", "? ", "? ", "? ", "? ", "? ", "? ")
scala> "?, " * 10                                                                                                    
res1: String = "?, ?, ?, ?, ?, ?, ?, ?, ?, ?, "
Minh Ha Pham
  • 2,566
  • 2
  • 28
  • 43