-2

I'm wondering if it's possible to convert an array of elements to the elements themselves. For my example, I'm trying to pass individual strings into a function whose arguments are a variable number of strings. I currently have an array of strings and am trying to pass them into .toDF (which takes a variable number of strings). This is what I have:

.toDF((df.columns)

How can I convert this array into the individual elements?

Jonathan Myers
  • 930
  • 6
  • 17
  • I would agree that the linked question describes what the operator does, but for those who do not know about the existence of such an operator, this question might be able to be found more easily. – Jonathan Myers Jun 28 '19 at 17:21
  • Don't think so, yours is less generic/self-answer – cchantep Jun 28 '19 at 19:08
  • Yes, mine is a self-answer, which StackOverflow actively gives support to doing. How would someone new to scala know to search for _* if they aren't aware of this operator and they run into this problem? This is a more queryable question than the one you say this is a duplicate of. Both provide the same answer to differently posed questions. – Jonathan Myers Jun 28 '19 at 22:44
  • That is precisely what duplicates are for: to serve as signposts with different search terms / different phrasing toward the answer *without fragmenting the answers between different questions*. – Jörg W Mittag Jun 29 '19 at 10:16

1 Answers1

2

You can do this with scala's splat operator (more information here):

.toDF(df.columns: _*)
Jonathan Myers
  • 930
  • 6
  • 17