0

I'm trying to get the equivalent of the following java code in scala for querying multiple keywords in twitter4j application

// In java
FilterQuery filterQuery = new FilterQuery();

String[] itemsToTrack = {"python", "java", "php"};

filterQuery.track(itemsToTrack);

twitterStream.filter(filterQuery);

// In scala I have written
val itemsToTrack = Array("python", "java", "php")
val filterQuery = new FilterQuery()
filterQuery.track(itemsToTrack) 

Above line gives error as it is expecting a string rather than a string array.

So my question is what if the equivalent of java code above using scala for querying multiple keywords in scala.

NOTE - > I'm new in scala

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

filterQuery.track is a Java function with a variable number of arguments. Its definition is:

public FilterQuery track(java.lang.String... track)

To call such a method from Scala, you would normally use this syntax:

filterQuery.track("java", "python", "scala")

If the arguments are already in an Array or another kind of sequence, you can use:

filterQuery.track(itemsToTrack:_*)

See also: Scala: pass Seq to var-args functions

Community
  • 1
  • 1
Wiebe
  • 106
  • 3