Option 1: List of maps. Not type-safe, since we don't declare exact value types.
List<Map<String, ?>> list = List.of(
Map.of(
"key1", 0,
"key2", 1,
"key3", "string"
),
Map.of(
"key1", 1,
"key2", 2,
"key3", "string2"
)
);
Option 2: Array of POJOs. Type-safe, since all values are explicitly typed.
MyObj[] array = { new MyObj(0, 1, "string"),
new MyObj(1, 2, "string2") };
public class MyObj {
private int key1;
private int key2;
private String key3;
public MyObj() {
}
public MyObj(int key1, int key2, String key3) {
this.key1 = key1;
this.key2 = key2;
this.key3 = key3;
}
public int getKey1() {
return this.key1;
}
public void setKey1(int key1) {
this.key1 = key1;
}
public int getKey2() {
return this.key2;
}
public void setKey2(int key2) {
this.key2 = key2;
}
public String getKey3() {
return this.key3;
}
public void setKey3(String key3) {
this.key3 = key3;
}
}
List vs array can of course go either way, I just wanted to show both options there too.