Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7784425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T20:05:35+00:00 2026-06-01T20:05:35+00:00

I have a java.util.Treemap[Long, Int] in Scala. What I need to do is convert

  • 0

I have a java.util.Treemap[Long, Int] in Scala. What I need to do is convert the values in the Treemap into an Array[Int].

I can either get an Iterator[Int] or Collection[Int] from the TreeMap, but I’m not sure how to convert these into an Array[Int].

Any suggestions would be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T20:05:36+00:00Added an answer on June 1, 2026 at 8:05 pm

    The problem with t.values.toArray is that java.util.Collection already has a toArray() method, which is why it returns an Integer[] which looks like an Array[AnyRef] to Scala. If Java didn’t have such a method, the implicit in JavaConversions would kick in and covert it to to an Iterable[Int] before building the Array. So you can either call the coversion explicitly or give a type hint:

    import collection.JavaConversions._    
    
    (t.values: Iterable[Int]).toArray
    

    or alternatively

    import collection.JavaConverters._
    
    t.values.asScala.toArray
    

    On my machine these are over twice about 30 times as fast as using toMap, for a 1000-entry TreeMap.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have tree with the following node spec: java.util.TreeMap<Long id, java.util.TreeMap children> When I
I have a java.util.Set<City> cities and I need to add cities to this set
On a JSTL/JSP page, I have a java.util.Date object from my application. I need
I have a Java application and I need to call into a Windows DLL
I have two Java instances of java.util.Date and I have to find out if
Let's say I have a java.util.Properties object. The Properties object has a method called
I have a simple code below: import java.util.ArrayList; public class BoidList extends ArrayList {
I have the following implicit conversion for java.util.Enumerations implicit def enumerationIterator[A](e : Enumeration[A]) :
I have an application that passes in java.util.Date. I want to check whether this
I have a field aliases of type java.util.Set in one Entity . This Set

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.