Scala Collections - Map

preview_player
Показать описание
Connect with me or follow me at
Рекомендации по теме
Комментарии
Автор

Hi Sir,

For the last problem, I think keys are duplicated. That's why we are getting only one key and value pair.

In your case:
scala> m.mapValues(order => (order.orderDate, order.orderStatus))
res56: scala.collection.Map[Int, (String, String)] = Map(2 -> (2017-01-01, CLOSED), 1 -> (2017-01-01, COMPLETE), 3 -> (2017-01-01, PENDING))

scala> m.mapValues(order => (order.orderDate, order.orderStatus)).map(rec => rec._2)
res57: scala.collection.Map[String, String] = Map(2017-01-01 -> PENDING)


Input to Map is :
(2017-01-01, CLOSED)
(2017-01-01, COMPLETE)
(2017-01-01, PENDING)

Output from Map is:
(2017-01-01, PENDING)

So this is expected.


In Java Map collection:
Map m = new HashMap();
m.put(1, "Technology Mentor");
m.put(1, "Itversity");
System.out.println(m);

Output for the above program is: {1=Itversity}

vengala