big_Xplosion
big_Xplosion

Reputation: 65

Loop through scala ListBuffer in java

If it is possible, how would I loop through a ListBuffer from within java. initialization of the ListBuffer (in scala)

var newModVersions: ListBuffer[NewModVersionEntry] = new ListBuffer[NewModVersionEntry]()

current smart for loop (in java)

for (VersionCheckHandler.NewModVersionEntry entry : XplosionCoreBL.newModVersions())

Upvotes: 3

Views: 963

Answers (1)

mikołak
mikołak

Reputation: 9705

You can use JavaConversions for that:

import scala.collection.JavaConversions;
//...
for (YourEntryClass entry : JavaConversions.asJavaIterable(yourListBuffer)) {

(I've switched to placeholder types and vars, since otherwise the example would be less readable)

See this answer to an "inverse" question for general info, and this question+answer for an explanation of the design approach taken in the Scala library.

Upvotes: 5

Related Questions