(六)java的map和scala的map互相转换
1:java的map转scala的map//java的map转为scala的immutable.mapprivate static scala.collection.immutable.Map<String,String> JavaMapToScala(Map kafkaparams) {Map<String, String> javamap ...
·
文章目录
1:java的map转scala的map
//java的map转为scala的immutable.map
private static scala.collection.immutable.Map<String,String> JavaMapToScala(Map kafkaparams) {
Map<String, String> javamap = new HashMap<>();
scala.collection.mutable.Map scalaMap = JavaConversions.mapAsScalaMap(javamap);
Object objTest = Map$.MODULE$.<String,String>newBuilder().$plus$plus$eq(scalaMap.toSeq());
Object resultTest = ((scala.collection.mutable.Builder) objTest).result();
scala.collection.immutable.Map<String,String> scala_imMap = (scala.collection.immutable.Map)resultTest;
return scala_imMap;
}
2:scala的immutable和java的mutable的map转换
2.1:mutable.Map to immutable.Map
val map = mutable.Map(1 -> "zhangsan", 2 -> "lisi")
val result = map.toMap
2.2:immutable.Map to mutable.Map
val map = immutable.Map(1 -> "zhangsan", 2 -> "lisi")
val result = mutable.Map(map.toSeq: _*)
更多推荐
已为社区贡献4条内容
所有评论(0)