利用HashMap存取对象
来源:互联网 发布:base64解码 js 编辑:程序博客网 时间:2024/05/23 01:20
1.HashMap 已实现的接口
Serializable, Cloneable, Map<K,V>
2.方法摘要
相关代码(Customer 类)
/** * * @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(); }
0 0
- 利用HashMap存取对象
- HashMap练习(存取对象)
- HashMap的存取
- HashMap详细的存取
- 利用HashMap辅助调整对象结构
- HTML5利用json对象来存取复杂数据
- HashMap的存取之美
- HashMap的存取之美
- HashMap存取元素原理分析
- HashMap(1): 基本存取原理
- 利用数据库存取文件
- 利用key,value形式储存对象的类(Map,HashMap)
- hashset()的桶式结构,利用hashset()存储对象,存取速度快
- SharedPreferences存取对象
- Hibernate实现存取对象
- Java map 存取对象
- Redis存取对象
- 04.01-JDBC通过hashmap存取数据
- Daoism --4
- cocos2d游戏开发常用工具集
- 12个小球 梅氏砝码问题
- 外链建设小妙招 如何通过外链吸引流量
- 生产者与消费者问题
- 利用HashMap存取对象
- CentOS6.5下用Git克隆代码(https方式)
- 单页网站如何做SEO优化排名呢
- 以英文逗点 , 分割的手机号 正则写法
- Centos搭建SVN服务器三步曲
- HDU 4442 贪心
- <!DOCTYPE html>很重要
- Linux kernel boot process——从实模式(real mode)到保护模式(protected mode),再到分页(paging)
- hdu 4442 Physical Examination (排序)