RandomAccessSubList is not serializable

I am trying to get a sublist List, but I want the sublist to be serialized. I found out that when we get a sublist from ArrayList, the sublist is not serialized.

To overcome this, this is what I do:

ArrayList serializedSublist = new ArrayList();
//getQuestions() returns RandomAccessSubList
getQuestions().addAll(serializedSublist); 
//problem is in the line below. serializedSublist is empty.
getRequest().getSession().setAttribute("questionsForUser", serializedSublist);

The problem is that it is serializedSubListempty on line 5, but on line 3 the getQuestions()list goes back.

0
source share
1 answer

You add it back, no? Must not be

serializedSublist.addAll(getQuestions());

or better yet

ArrayList serializedSublist = new ArrayList(getQuestions());
+7
source

All Articles