I am writing some scala code which uses the API. I want to redo the rows contained in the java.util.Iterator
which I get from the sheet class. I want to use iterator in a for each
style loop, so I'm trying to convert it to a native scala archive, but no luck.
I will notice Skala wrapper sections / symptoms, but I can not see how to use them correctly, without using verbose I have to iterate more than a Java compile in Scala , While (hasNext ()) getNext ()
the style of the loop?
Here the code I wrote is correct based on the answer:
class IteratorWrapper [A] (ITER: java.util.Iterator [A]) {def foreach (f : A => unit: {while (iter.hasNext) {f (iter.next)}}} Object SpreadsheetParser application {iteratorToWrapper [T] Diff extends contained (ITER: java.util.Iterator [T] ): IteratorWrapper [T] New IteratorWrapper [T] (ITER =) Def override main (args: array [string]): unit = {val ios = new FileInputStream ("property / data.xls") Val workbook = new HSSFWorkbook ( IOS) on sheet = worksbook.getSheetAt (0) rows = sheet.rowIterator {Textln (line)}}}
is a wrapper class ( scala.collection.jcl.MutableIterator's cover
). If you define
embedded def javaIteratorToScalaIterator [A] (this: java.util.Iterator [A]) = new wrapper (this)
Then it will function as a subclass of Scala Itater so that you can do foreach
.
Comments
Post a Comment