0

I want to convert a scala Seq to Java java.util.Enumeration any tips?

Boynux
  • 5,958
  • 2
  • 21
  • 29
  • Why? What do you need an `Enumeration` for? – sepp2k May 08 '17 at 12:06
  • 2
    What did you try or find already? For example, http://stackoverflow.com/a/5184386/2308683 – OneCricketeer May 08 '17 at 12:06
  • can you give a few more details? it seems an odd use case. Maybe you have a List of Strings and you want to convert each to one of the possible Enumeration values? – pedrorijo91 May 08 '17 at 12:29
  • 1
    @pedrorijo91 `java.util.Enumeration` has nothing to do with enums. It's a pre-Java 1.2 version of `java.util.Iterator`. – sepp2k May 08 '17 at 12:43
  • 1
    The issue is I'm using a library that needs an Enumeration as argument to functions. but I have a Set in Scala. The Solution was to use `asEnumeration(someSet)` in JavaConvertors. – Boynux May 09 '17 at 09:23

2 Answers2

1

In case someone else is interested in the answer:

By importing scala.collection.JavaConversions I could use asJavaEnumeration[A](i: Iterator[A]): Enumeration[A] to do the job.

Boynux
  • 5,958
  • 2
  • 21
  • 29
0

Enumeration is basically an outdated thing. It is one of those concepts that were introduced with Java 1.0, but that nobody would / should be using any more nowadays.

In 2017, you use collections. In other words: if at all, you turn your Seq into a List. You can read about how to do that here.

Community
  • 1
  • 1
GhostCat
  • 137,827
  • 25
  • 176
  • 248