serialization ArrayList Java

2019-01-19 15:59发布

I want to serialize the Arraylist of type ArrayList<Class> and the class contains two Arraylist of primitive type

public class Keyword {

    private long id;
    private long wid;
    private String name;
    private ArrayList<Integer> rank;
    private int month;
    private float avg;
    private ArrayList<String> date;
        ... and so on
}

How can i do that?

Lots of thanks in advance

3条回答
做个烂人
2楼-- · 2019-01-19 16:28

Implement and Interface public class Keyword implements Serializable {} and Simply Use the method of "Object output stream" and "Object input stream" to Serialize and De-serialize the object.

and Arrylist can be Serialize as normal any data type can serialized.

查看更多
姐就是有狂的资本
3楼-- · 2019-01-19 16:30

inherit the serialization interface in the that class which calss object you want to serialize.

after that use the ObjectOutput for serialize the object and use the writeObject method for serialize the object.

查看更多
在下西门庆
4楼-- · 2019-01-19 16:50

If you want to use Serializable, you should have no problems, because ArrayList is Serializable just as String and every primitive type. public class Keyword implements Serializable {} should do. You can read more about this method here. However there are a lot of other options for serialization. So please be more specific.

查看更多
登录 后发表回答