12
Mar

Serialization / Deserialization of HashMap in java
    String name = "JackychanAdventuresJJ";

    Map<Character, Integer> map = new LinkedHashMap<>();

    for (Character c : name.toCharArray()) {
        map.put(c, map.containsKey(c) ? (map.get(c) + 1) : 1);
    }

    System.out.println(map);

    try {
        ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream("C:\\abc.ser"));
        oos.writeObject(map);
        oos.close();

        ObjectInputStream ois = new ObjectInputStream(new FileInputStream("C:\\abc.ser"));
        Map<Character, Integer> mapD = (Map<Character, Integer>) ois.readObject();
        for (Map.Entry<Character, Integer> me : mapD.entrySet()) {
            System.out.print(me.getKey() + "::" + me.getValue());
        }

    } catch (IOException | ClassNotFoundException e) {

        e.printStackTrace();
    }