I would like to convert a Map[Int, Any] to a SortedMap or a TreeMap. Is there an easy way to do it?
I would like to convert a Map[Int, Any] to a SortedMap or a TreeMap
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Assuming you’re using immutable maps
The
TreeMapcompanion object’s apply method takes repeated map entry parameters (which are instances ofTuple2[_, _]of the appropriate parameter types).toArrayproduces anArray[Tuple2[Int, String]](in this particular case). The: _*tells the compiler that the array’s contents are to be treated as repeated parameters.