ContentValues(Java)
2015-12-13 19:32
337 查看
在SDK中,ContentValues的介绍为:
This class is used to store a set of values that the ContentResolver can process.
就是用于保存一些数据(string/boolean/byte/double/float/int/long/short …)信息,这些信息可以被数据库操作时方便地使用。
ContentValues 和 HashTable 类似,都是一种存储的机制,但是两者最大的区别就在于:ContentValues 只能存储基本类型的数据,像string、int之类的,不能存储对象这种东西,而HashTable却可以存储对象。
一些常用的方法如下:
比如向 SQLite 数据库中插入数据的时候,首先应该有一个ContentValues的对象:
插入成功就返回记录的id,否则返回-1.
说明:ContentValues是基于HashMap的,这与HashTable是不同的。
下面简要说一下HashMap与HashTable的区别:
Hashtable 继承自 Dictiionary 而 HashMap继承自AbstractMap。
Hashtable的方法是Synchronize的,而HashMap不是,在多个线程访问Hashtable时,不需要自己为它的方法实现同步,而HashMap 就必须为之提供外同步。
Hashtable中,key和value都不允许出现null值。在HashMap中,null可以作为键,这样的键只有一个;可以有一个或多个键所对应的值为null。当get()方法返回null值时,即可以表示 HashMap中没有该键,也可以表示该键所对应的值为null。因此,在HashMap中不能由get()方法来判断HashMap中是否存在某个键, 而应该用containsKey()方法来判断。
This class is used to store a set of values that the ContentResolver can process.
就是用于保存一些数据(string/boolean/byte/double/float/int/long/short …)信息,这些信息可以被数据库操作时方便地使用。
ContentValues 和 HashTable 类似,都是一种存储的机制,但是两者最大的区别就在于:ContentValues 只能存储基本类型的数据,像string、int之类的,不能存储对象这种东西,而HashTable却可以存储对象。
一些常用的方法如下:
ContentValues() Creates an empty set of values using the default initial size
ContentValues(int size) Creates an empty set of values using the given initial size
ContentValues(ContentValues from) Creates a set of values copied from the given set
比如向 SQLite 数据库中插入数据的时候,首先应该有一个ContentValues的对象:
ContentValues cv = new ContentValues(); //创建对象 cv.put(key,values); // 赋值 SQLiteDataBase sdb ; // 创建数据库 sdb.insert(database_name,null,initialValues); // 将数据插入数据库
插入成功就返回记录的id,否则返回-1.
说明:ContentValues是基于HashMap的,这与HashTable是不同的。
下面简要说一下HashMap与HashTable的区别:
Hashtable 继承自 Dictiionary 而 HashMap继承自AbstractMap。
Hashtable的方法是Synchronize的,而HashMap不是,在多个线程访问Hashtable时,不需要自己为它的方法实现同步,而HashMap 就必须为之提供外同步。
Hashtable中,key和value都不允许出现null值。在HashMap中,null可以作为键,这样的键只有一个;可以有一个或多个键所对应的值为null。当get()方法返回null值时,即可以表示 HashMap中没有该键,也可以表示该键所对应的值为null。因此,在HashMap中不能由get()方法来判断HashMap中是否存在某个键, 而应该用containsKey()方法来判断。
相关文章推荐
- LeetCode 232:Implement Queue using Stacks
- 关于ueditor 1.4.3 上传小于1M图片时不压缩的bug修正
- IPad专有API UISplitViewController开发菜单浏览demo
- Cannot convert value of type [com.sun.proxy.$Proxy11 implementing com.xuyp.managize.service.IBaseSer
- org.hibernate.NonUniqueResultException: query did not return a unique result: 2
- ueditor1.4.3jsp版成功上传图片后却回显不出来与在线管理显示不出图片的解决方案
- java中PriorityQueue优先级队列的使用
- UITableView基础
- StringBuilder源码分析
- UVA 11235 Frequent values
- hibernate query.list() 返回的数据类型
- UiAutomator无法识别popupwindow的解决方法
- 蓝鸥 UI 考试 绝密
- iOS UI 21 消息通知
- iOS UI 21 消息通知
- iOS UI 21 单例中的线程
- iOS UI 21 单例中的线程
- iOS UI 21 线程
- iOS UI 21 线程
- iOS UI 21 动画