Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Semrush - keyword research tool

Turn ChatGPT, Claude, Gemini, And CoPilot Into Your Personal Assistant, Business Coach, Content Creator, And More

AFFILIATE MARKETING Your all-in-one performance engine Manage affiliates, creators, and customer referrals in one unified platform—turning every partnership into measurable growth
Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

42,844 questions

55,671 answers

573 users

How to create multi-dimensional array in Scala

1 Answer

0 votes
val rows = 2
val cols = 3
val arr2d = Array.ofDim[String](rows, cols)

// row 0 (1)
arr2d(0)(0) = "Arthur"
arr2d(0)(1) = "Albus"
arr2d(0)(2) = "Alia"

// row 1 (2)
arr2d(1)(0) = "Artemis"
arr2d(1)(1) = "Deckard"
arr2d(1)(2) = "Dana"

for (i <- 0 until rows; j <- 0 until cols) {
  println(s"($i)($j) = ${arr2d(i)(j)}")
}


 
/*
run:

(0)(0) = Arthur
(0)(1) = Albus
(0)(2) = Alia
(1)(0) = Artemis
(1)(1) = Deckard
(1)(2) = Dana

*/

 



answered May 29, 2025 by avibootz
...