You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by "Kumari, Ramana" <Ra...@DFA.STATE.NY.US> on 2002/03/29 18:16:07 UTC
about ArrayList
Hi
My question is not really related to Struts, but i thought i could ask
you guys about this so that i can get some answer &
this might help some developers.
When i looked at the source code for Sun's Java class ArrayList i found
something interesting.
The private member of the ArrayList class, which holds the objects added
to list, is transient which means indication to the Java virtual machine
that the indicated variable is not part of the persistent state of the
object.
So My question is
if i have an ArrayList object, can i save this object into a file & read
the same object from the file without loosing data ?
(Keep in mind the member variable, private transient Object
elementData[]; , which holds tha actual data is transient in ArrayList)
Please see below for Some code from java.util.ArrayList.java
Thanks in advance
Ramana
public class ArrayList extends AbstractList implements List, Cloneable,
java.io.Serializable {
private transient Object elementData[];
private int size;
public ArrayList(int initialCapacity) {
super();
this.elementData = new Object[initialCapacity];
}
public ArrayList() {
this(10);
}
public ArrayList(Collection c) {
size = c.size();
elementData = new Object[(size*110)/100]; // Allow 10% room for
growth
c.toArray(elementData);
}
public void trimToSize() {
modCount++;
int oldCapacity = elementData.length;
if (size < oldCapacity) {
Object oldData[] = elementData;
elementData = new Object[size];
System.arraycopy(oldData, 0, elementData, 0, size);
}
}
}
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: about ArrayList
Posted by Jim Crossley <jc...@ifleet.com>.
"Kumari, Ramana" <Ra...@DFA.STATE.NY.US> writes:
> My question is not really related to Struts, but i thought i could
> ask you guys about this so that i can get some answer & this might
> help some developers.
Maybe, but it's still not an appropriate list topic.
> So My question is if i have an ArrayList object, can i save this
> object into a file & read the same object from the file without
> loosing data ?
Yes. All java.util.Collection implementations are serializable.
> (Keep in mind the member variable, private transient Object >
> elementData[]; , which holds tha actual data is transient in >
> ArrayList)
That's only half the story. The rest of the story may be read in the
ArrayList's readObject and writeObject methods.
-- Jim
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>