Skip to main content

2-D Array

2 replies [Last post]
rabinovic
Offline
Joined: 2007-12-02

Hi,

I would like to know how can I create a 2-dimensional array like in java:

int[][] array1 = new int[10][20];

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
rabinovic
Offline
Joined: 2007-12-02

I tried it with compiled javafx. It looks very simple:

import java.lang.System;

class Array2d{
attribute f:Integer[];
}

var s:Array2d[];

for(i in [1..5]){
insert Array2d{} into s;
}

for(k in [0..4], j in [0..4]){
insert j*2 into s[k].f;
}

System.out.println(s[0].f[2]); // 4
System.out.println(s[1].f[0]); // 0
System.out.println(s[2].f[1]); // 2
System.out.println(s[3].f[4]); // 8
System.out.println(s[4].f[2]); // 4

pforhan
Offline
Joined: 2003-08-07

According to https://openjfx.dev.java.net/JavaFX_Programming_Language.html#func_arrays :
"
Arrays represent sequences of objects. In JavaFX arrays are not themselves objects, however, and do not nest. Expressions that produce nested arrays are automaticallly flattened...
"

To do something like a 2d array, you could define an object that itself has an array of objects...

-----------
class Column {
attribute value:String;
}

class Row {
attribute columns:Column*;
}

var rows:Row* = [
Row {
columns: [
Column {
value: "Val1"
},
]
}
];

println(rows[0].columns[0].value);
-----------

Pat.