簡體   English   中英

如何將java代碼中的二維字符串數組傳遞給play框架中的scala.html?

[英]How to pass a 2 dimensional string array from java code to scala.html in play framework?

我有一個問題,它給我一個錯誤"'[' expected but integer literal found"初始化數組字符串數組"arr[i][j]="string";" 我所有的初始化。 我想在HTML視圖的表中顯示這個2D數組

因為這個答案指定Java數組直接映射到Scala 而且,在Scala ,要訪問collection的元素,您需要使用apply()方法,該方法等同於()


val arr = Array.fill(3,3)("hello")
// Displays
//arr: Array[Array[String]] = Array(
//  Array("hello", "hello", "hello"),
//  Array("hello", "hello", "hello"),
//  Array("hello", "hello", "hello")
//)

val row0 = arr.apply(0)
//Displays
//row0: Array[String] = Array("hello", "hello", "hello")

val row1 = arr(1)
//Display
//row1: Array[String] = Array("hello", "hello", "hello")

val elem11 = row1(1)
//elem11: String = "hello"

以下是更新元素的方法:

arr(1)(1) = "string"

arr.map(_.mkString(",")).mkString("\n")
// Displays
//res9: String = """hello,hello,hello
//hello,string,hello
//hello,hello,hello"

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM