Dave's Brain

Browse - Programming Tips - How can I iterate through an ArrayList in Scala?

Date: 2013may22
Language: Scala
Keywords: enumerate

Q.  How can I iterate through an ArrayList in Scala?

A.  If you have a legacy Java function that returns an ArrayList<>
you can iterate this way:

import collection.JavaConversions._ for (str <- asScalaBuffer(OldCode.oldFunction())) { System.out.println(str); }
OldCode.oldFunction() is your legacy function. asScalaBuffer() converts your ArrayList. It can be an ArrayList of anything.

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.