This page is no longer maintained — Please continue to the home page at www.scala-lang.org

2.8.0 converting from Java List to Scala List

2 replies
rossputin
Joined: 2009-02-26,
User offline. Last seen 2 years 12 weeks ago.

Hi Guys.

In my continued update from 2.7.5 to 2.8.0, I am now addressing the issue of
converting from Java Lists to Scala Lists to be able to enjoy the added
niceness (foreach, filter etc etc) of Scala Lists. I used to use something
along the lines of :

def toList[T](list: java.util.List[T]) = new BufferWrapper[T] { def
underlying = list }

for lists, and :

def toMap[K, E](m: java.util.Map[K, E]) = new MapWrapper[K, E] { def
underlying = m }

for maps, using scala.collection.jcl.BufferWrapper, and
scala.collection.jcl.MapWrapper.

How do I do this in 2.8.0? Can anyone point me to the docs?

Thanks in advance for your help,

regards

Kevin Wright
Joined: 2009-06-09,
User offline. Last seen 49 weeks 3 days ago.
Re: 2.8.0 converting from Java List to Scala List
I'm pretty sure that all the necessary implicits are now in place and working as expected
Just import scala.collection.JavaConversions._ then simply use any scala method you wish on a java list and enjoy the results.

On Wed, Aug 12, 2009 at 11:23 AM, rossputin <rossajmcd [at] yahoo [dot] co [dot] uk> wrote:

Hi Guys.

In my continued update from 2.7.5 to 2.8.0, I am now addressing the issue of
converting from Java Lists to Scala Lists to be able to enjoy the added
niceness (foreach, filter etc etc) of Scala Lists.  I used to use something
along the lines of :

def toList[T](list: java.util.List[T]) = new BufferWrapper[T] { def
underlying = list }

for lists, and :

def toMap[K, E](m: java.util.Map[K, E]) = new MapWrapper[K, E] { def
underlying = m }

for maps, using scala.collection.jcl.BufferWrapper, and
scala.collection.jcl.MapWrapper.

How do I do this in 2.8.0?  Can anyone point me to the docs?

Thanks in advance for your help,

regards

rossputin
Joined: 2009-02-26,
User offline. Last seen 2 years 12 weeks ago.
Re: 2.8.0 converting from Java List to Scala List

Hi Kevin.

Thats great, thanks!

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland