【发布时间】:2014-10-20 17:26:02
【问题描述】:
我有这样的东西(非常简化的版本):
public class TransferData implements Serializable{
private Collection[] collections;
private String ID;
public TransferData( Collection[] collections){
this.ID = ID;
this.collections = collections;
}
public String getID(){
return ID;
}
public Collection[] getCollections(){
return collections;
}
}
这是我通常抓取物品的方式:
//Save object in db
ContentValues values = new ContentValues();
values.put("id", td.getID());
但是,我无法理解如何从可序列化类中的集合/数组中获取项目?
这没有意义:
ContentValues values = new ContentValues();
values.put("collectionitem1", td.getCollections()); ??? //need to index the array, how?
我试过这样的:
for (int i=0; i <= td.getCollections().length; i++) {
System.out.println(i);
}
但奇怪的是只给了我 3 个索引而不是数组中的 4 个索引,但这对我没有帮助。此外,我的数组包含字符串和整数,因此可能很难使用 foreach 样式循环进行索引。
【问题讨论】:
-
你应该解释
values是什么类型,没人知道你的上下文 -
抱歉,我的意思是:ContentValues values = new ContentValues();
标签: java arrays sqlite serialization