3维列表或地图 [英] 3-Dimension List or Map
本文介绍了3维列表或地图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要的东西就像一个3维(如列表或地图),我充满了2串一个循环内的整数。但不幸的是,我不知道用哪个数据结构,以及如何。
//像一个三维的myData
对(INT I = 0; I&小于10;我++){
myData.add(ABC,高清,123);
}
解决方案
创建一个封装三者合计的对象,并将其添加到一个数组或列表:
公共类Foo {
私人字符串S1;
私人字符串s2;
私人诠释V3;
//构建函数,干将等
}清单<富> FOOS =新的ArrayList<富>();
对(INT I = 0; I&小于10 ++ⅰ){
foos.add(新富(ABC,高清,123);
}
如果要插入到数据库中,写一个DAO类:
公共接口FooDao {
而无效(美孚富);
}
实施为使用JDBC必要的。
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);
}
解决方案
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.
这篇关于3维列表或地图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文