利用HashMap存取对象并获得键值集合
1.HashMap 已实现的接口
Serializable, Cloneable, Map<K,V>
2.方法摘要
相关代码
/**
*
* @param ha
* write(HashMap<String,Customer> ha) 传来HashMap对象列表 将对象写入文件中
*/
public static void write(HashMap<String, Customer> ha) {
;
try {
ObjectOutputStream oos = new ObjectOutputStream(
new FileOutputStream("e:/db/db.dat"));
oos.writeObject(ha);
oos.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} /**
* @param id
* @return ReadCustomer(String id) 方法 通过HashMap 关键字 读取对象 并且返回对象
*/
public static Customer readCustomer(String mark) {
HashMap<String, Customer> hm = new HashMap<String, Customer>();
Customer c = new Customer();
try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"e:/db/db.dat"));
hm = (HashMap<String, Customer>) ois.readObject();
c = hm.get(mark);
ois.close(); } catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
return c;
}
/**
* writeCustomer(Customer cus) 将对象写入HashMap 列表中并通过write()方法将对象写入文件中
*
* @param account
*/
public static void writeCustomer(Customer cus) {
HashMap<String, Customer> m = new HashMap<String, Customer>(); try {
ObjectInputStream ois = new ObjectInputStream(new FileInputStream(
"e:db/db.dat"));
m = (HashMap<String, Customer>) ois.readObject();
m.put(cus.getMark(), cus);
write(m);
ois.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Util.stay();
}
利用HashMap存取对象并获得键值集合的更多相关文章
- Hashtable键值集合
//Hashtable键值集合 键必须是维一的 类似于索引 Hashtable ht = new Hashtable(); ht.Add(, "中国"); ht.Add(, ); ...
- 键值集合List转换成datatable
/// <summary> /// 键值集合List转换成datatable /// </summary> /// <param name="data" ...
- 利用GeneratedKeyHolder获得新增数据主键值
Spring利用GeneratedKeyHolder,提供了一个可以返回新增记录所对应的主键值的方法: int update(PreparedStatementCreator psc, KeyHold ...
- hashmap可以用null为键值
import java.util.HashMap; import java.util.Map; import java.util.TreeMap; public class TestMain { ...
- JArray数组每个JObject对象添加一个键值对
JArray ja = new JArray(); JObject jo = new JObject(); jo.Add("1","1"); ja.Add(jo ...
- mybatis插入值的时候返回对象的主键值
mapping文件: <insert id="insert" parameterType="com.vimtech.bms.business.riskproject ...
- 将字符串转换成C#认可的对象(有键值对的对象)
var resobj = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(result ...
- Android(java)学习笔记105:Map集合的遍历之键值对对象找键和值
package cn.itcast_01; import java.util.HashMap; import java.util.Map; import java.util.Set; /* * Map ...
- Java基础知识强化之集合框架笔记53:Map集合之Map集合的遍历 键值对对象找键和值
1. Map集合的遍历(键值对对象找键和值) Map -- 夫妻对 思路: A: 获取所有结婚证的集合 B: 遍历结婚证的集合,得到每一个结婚证 C: 根据结婚证获取丈夫和妻子 转换: A: ...
随机推荐
- java打开本地应用程序(调用cmd)---Runtime用法详解
有时候我们需要借助java程序打开电脑自带的一些程序,可以直接打开或者借助cmd命令窗口打开一些常用的应用程序或者脚本,在cmd窗口执行的命令都可以通过这种方式运行. 例如: package cn.x ...
- apache + DSO -动态共享对象(DSO)
http://www.jinbuguo.com/apache/menu22/dso.html
- ThinkPHP __construct和_initialize的使用
ThinkPHP框架中的__construct和_initialize的使用 父类(PlatformController.class.php): class PlatformController ex ...
- CSS介绍&选择器&选择器优先级
CSS介绍 CSS(Cascading Style Sheet,层叠样式表)定义如何显示HTML元素. 当浏览器读到一个样式表,它就会按照这个样式表来对文档进行格式化(渲染). CSS语法 '''se ...
- java、android拼音,中文姓名排序
http://blog.sina.com.cn/s/blog_81a9aa7e0100tizj.html 在java或者是android编程的时候,我们经常要用到对姓名或者其他字符串排序,现在我写写自 ...
- Spoj 3267 DQUERY - D-query
题目描述 English VietnameseGiven a sequence of n numbers a _{1}1 , a _{2}2 , ..., a _{n}n and a numbe ...
- openstack swift middleware开发
首先MiddleWare核心代码,这段代码卸载swift的源代码目录下,~/swift/swift/common/middleware下新建deletionpreventing.py: import ...
- 如何把你的Windows PC变成瘦客户机
越来越多的用户开始使用vmware view 4.5来做为企业桌面虚拟化的平台,通过view,所有的管理工作都转移到数据中心,但是考虑到成本原因,很多人员还在使用PC机,有没有办法将PC机变成瘦客户机 ...
- Oracle 数据库管理员的任务
设计.实施和维护 Oracle 数据库时,按优先次序排列的任务包括: 1. 确定数据库服务器硬件 2. 安装 Oracle 软件 3. 为数据库和安全策略制定计划 4. 创建.移植和打 ...
- 支付宝移动支付之IOSApp调用支付宝钱包
近期客户提出要开发一个IOS上的app作为訪问他们站点的途径之中的一个.为什么说之中的一个呢.因为眼下PC和Mobile这两个站眼下都已经上线了. 所以问题就简单了,我们仅仅须要把mobile站UI改 ...