Is there a way to take a java based API that loops over property names and someone add the key/value pairs to a Scala Map[String, Object] ?
Enumeration properties = something.getPropertyNames();
while (properties.hasMoreElements())
{
String propName = (String) srcProperties.nextElement();
Object v = something.getValue(propName);
}
I think you are confusing a Java Enumeration with the Properties object it was obtained from. Like in
Enumeration propertyNames = props.getPropertyNames()
We cannot create a map from the resulting Enumeration, because it's only a sequence of Strings, but we can obtain a Map[String,String] from the original Properties object.
import scala.collection.JavaConverters._
val propertyMap = props.asScala // mutable map
// or
val propertyMap = props.asScala.toMap // immutable map
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With