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

  • Home
  • SEARCH
  • 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 951245
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T23:42:13+00:00 2026-05-15T23:42:13+00:00

It seems like the support for printing arrays is somewhat lacking in Scala. If

  • 0

It seems like the support for printing arrays is somewhat lacking in Scala. If you print one, you get the default garbage you’d get in Java:

scala> val array = Array.fill(2,2)(0)             
array: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0))

scala> println(array)
[[I@d2f01d

Furthermore, you cannot use the Java toString/deepToString methods from the java.util.Arrays class: (or at least I cannot figure it out)

scala> println(java.util.Arrays.deepToString(array))
<console>:7: error: type mismatch;
 found   : Array[Array[Int]]
 required: Array[java.lang.Object]
       println(java.util.Arrays.deepToString(array))

The best solution I could find for printing a 2D array is to do the following:

scala> println(array.map(_.mkString(" ")).mkString("\n"))
0 0
0 0

Is there a more idiomatic way of doing this?

  • 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-05-15T23:42:14+00:00Added an answer on May 15, 2026 at 11:42 pm

    In Scala 2.8, you can use the deep method defined on Array, that returns an IndexedSeq cointaining all of the (possibly nested) elements of this array, and call mkString on that:

    
    scala> val array = Array.fill(2,2)(0)
    array: Array[Array[Int]] = Array(Array(0, 0), Array(0, 0))
    
    scala> println(array.deep.mkString("\n"))
    Array(0, 0)
    Array(0, 0)
    

    The IndexedSeq returned does have a stringprefix ‘Array’ by default, so I’m not sure whether this gives precisely what you wanted.

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

Sidebar

Related Questions

Is there any intrinsic support for namespacing in coffeescript? Adequate namespacing seems like something
I'd like to be sure if vestal_versions does support versioned associations (it seems like
Disclaimer: I am a n00b. It seems like ODBC does not support a BOOLEAN
There seems to only be 2nd class support for composite database keys in Java's
Seems like MySQL Bug; Request: SELECT * FROM table WHERE ( id LIKE '%тест
Seems like a simple enough question but I can't seem to find the answer.
Seems like a simple problem: I have an SVN repo inside our firewall. I
Seems like the subtraction is triggering some kind of issue and the resulting value
Seems like as really simple thing to do, but I just can't track it
Seems like cuke doesn't show the full error message (at least when problem occurs

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.