Issue
I need something like a 3-dimension (like a list or a map), which I fill with 2 Strings and an Integer within a loop. But, unfortunately I don't know which data structure to use and how.
// something like a 3-dimensional myData
for (int i = 0; i < 10; i++) {
myData.add("abc", "def", 123);
}
Solution
Create an object that encapsulates the three together and add them to an array or List:
public class Foo {
private String s1;
private String s2;
private int v3;
// ctors, getters, etc.
}
List<Foo> foos = new ArrayList<Foo>();
for (int i = 0; i < 10; ++i) {
foos.add(new Foo("abc", "def", 123);
}
If you want to insert into a database, write a DAO class:
public interface FooDao {
void save(Foo foo);
}
Implement as needed using JDBC.
Answered By - duffymo
Answer Checked By - Marilyn (JavaFixing Volunteer)