HashMap是一对键值
HashMap<key,values>一般都用来存放配对的数据
使用put方法可以存入多对
HashMap<String,String> hashMap = new HashMap<>();构造函数的类型会自匹配
hashMap.put("aaa", "bbb");
.....
.....
接下来就是遍历,有用迭代器的,有用entry的。
我个人比较喜欢用entrySet方便实用,我这里就举个例子,循环遍历一个HashMap的ArrayList
public void InsertValue(String tableName, ArrayList<HashMap<String, String>> dataList) {
ContentValues values = new ContentValues();
//开始组装数据
for (HashMap<String, String> hashMap : dataList) {
for (HashMap.Entry<String, String> entry : hashMap.entrySet()) {
values.put(entry.getKey(), entry.getValue());
}
this.db.insert(tableName, null, values);
values.clear();
}
}
这是一个SQLite插入的封装函数,很简单看看就会了