What is an easy way to initialize a matrix?
// something like this would be nice int[][] matrix = new int[][]{{1,2,3},{4,5,6},{7,8,9}};
if you want to determine the type of a variable, use this:
int[][] matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
if the variable is untyped, use this:
def matrix = [[1, 2, 3], [4, 5, 6], [7, 8, 9]] as int[][]
in groovysh i did
groovy:000> int[][] matrix = [[1,2,3],[4,5,6],[7,8,9]]; println matrix[1][1]; println matrix.class 5 class [[I ===> null
Please note that there is a warning "Be careful: we do not support the built-in multi-dimensional array creation right now." found here: http://groovy.codehaus.org/Migration+From+Classic+to+JSR+syntax
too, I put
assert matrix instanceof int[][]
at the end and seems to check.
Source: https://habr.com/ru/post/1792025/More articles:Не удается получить доступ к классам в пакете по умолчанию - javaDefining indexes for related models with Thinking Sphinx - ruby-on-railsGetting a submit form for a submit event - javascriptVector indexing for short - c ++will_paginate + jquery ui tabs - jqueryHow to replace svn subdirectory provider branch with git merging subtree - gitHow to get build time in .NET? - datetimeIncrease async_write problem - c ++Распечатайте что-то после успешного создания в Makefile.am - automakeHow to display the welcome screen in Android? - androidAll Articles