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存取对象并获得键值集合的更多相关文章

  1. Hashtable键值集合

    //Hashtable键值集合 键必须是维一的 类似于索引 Hashtable ht = new Hashtable(); ht.Add(, "中国"); ht.Add(, ); ...

  2. 键值集合List转换成datatable

    /// <summary> /// 键值集合List转换成datatable /// </summary> /// <param name="data" ...

  3. 利用GeneratedKeyHolder获得新增数据主键值

    Spring利用GeneratedKeyHolder,提供了一个可以返回新增记录所对应的主键值的方法: int update(PreparedStatementCreator psc, KeyHold ...

  4. hashmap可以用null为键值

    import java.util.HashMap; import java.util.Map; import java.util.TreeMap;   public class TestMain { ...

  5. JArray数组每个JObject对象添加一个键值对

    JArray ja = new JArray(); JObject jo = new JObject(); jo.Add("1","1"); ja.Add(jo ...

  6. mybatis插入值的时候返回对象的主键值

    mapping文件: <insert id="insert" parameterType="com.vimtech.bms.business.riskproject ...

  7. 将字符串转换成C#认可的对象(有键值对的对象)

    var resobj = Newtonsoft.Json.JsonConvert.DeserializeObject<Newtonsoft.Json.Linq.JArray>(result ...

  8. Android(java)学习笔记105:Map集合的遍历之键值对对象找键和值

    package cn.itcast_01; import java.util.HashMap; import java.util.Map; import java.util.Set; /* * Map ...

  9. Java基础知识强化之集合框架笔记53:Map集合之Map集合的遍历 键值对对象找键和值

    1. Map集合的遍历(键值对对象找键和值) Map -- 夫妻对  思路:  A: 获取所有结婚证的集合  B: 遍历结婚证的集合,得到每一个结婚证  C: 根据结婚证获取丈夫和妻子 转换:  A: ...

随机推荐

  1. docker持续集成部署、csphere监控平台【转:http://blog.csdn.net/java_dyq/article/details/51997024】

    为什么使用Docker “ 从我个人使用的角度讲的话  部署来的更方便 只要构建过一次环境 推送到镜像仓库 迁移起来也是分分钟的事情 虚拟化让集群的管理和控制部署都更方便 hub.docker.com ...

  2. (在线工具)JSON字符串转换成Java实体类(POJO)

    http://www.bejson.com/json2javapojo/ 付代码代码转换示例: public static FixMixedOrderResponse serialization(St ...

  3. Windows Server 2003的一些优化设置 (转至网络)

    2003序列号:JCHKR-888KX-27HVK-DT88X-T767M1.禁用配置服务器向导: 禁止“配置你的服务器”(Manage Your Server)向导的出现:在控制面板(Control ...

  4. 【搜索引擎】SOLR VS Elasticsearch(2019技术选型参考)

    SOLR是什么 (官方的解释) Solr是基于Apache Lucene构建的流行的.快速的.开源的企业搜索平台. Solr也是高度可靠.可伸缩和容错的,提供分布式索引.复制和负载平衡查询.自动故障转 ...

  5. uva558 Wormholes SPFA 求是否存在负环

    J - Wormholes Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Stat ...

  6. 【转】JavaScript错误处理和堆栈追踪

    原文: https://www.cnblogs.com/caoru/p/6699583.html --------------------------------------------------- ...

  7. AngularJS - $index, $event, $log

    原文: https://thinkster.io/egghead/index-event-log --------------------------------------------------- ...

  8. libpython2.7.so.1.0: cannot open shared object file: No such file or directory

    解决方法如下: 1.编辑      vi /etc/ld.so.conf  如果是非root权限帐号登录,使用 sudo vi /etc/ld.so.conf  添加上python2.7的lib库地址 ...

  9. [RxJS] Implement RxJS `mergeMap` through inner Observables to Subscribe and Pass Values Through

    Understanding sources and subscribers makes it much easier to understand what's going on with mergeM ...

  10. 看懂JSP声明的格式。。。

    在WebRoot下新建test3.jsp 改动body内容: <%! int a = 3; %>     <% int b = 3; %>     <%= a--  %& ...