Path: csiph.com!x330-a1.tempe.blueboxinc.net!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!nx01.iad01.newshosting.com!newshosting.com!69.16.185.16.MISMATCH!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!glegroupsg2000goo.googlegroups.com!not-for-mail From: Lew Newsgroups: comp.lang.java.programmer Subject: Re: Size of an arraylist in bytes Date: Sun, 20 Nov 2011 20:28:16 -0800 (PST) Organization: http://groups.google.com Lines: 49 Message-ID: <23614233.2468.1321849696743.JavaMail.geo-discussion-forums@prfx4> References: <278f7e6f-ee15-4ceb-bad7-fbb5f3e1e90b@h30g2000pro.googlegroups.com> Reply-To: comp.lang.java.programmer@googlegroups.com NNTP-Posting-Host: 173.164.137.214 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1321849698 27374 127.0.0.1 (21 Nov 2011 04:28:18 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 21 Nov 2011 04:28:18 +0000 (UTC) In-Reply-To: <278f7e6f-ee15-4ceb-bad7-fbb5f3e1e90b@h30g2000pro.googlegroups.com> Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=173.164.137.214; posting-account=CP-lKQoAAAAGtB5diOuGlDQk0jIwmH0T User-Agent: G2/1.0 X-Google-Web-Client: true Xref: x330-a1.tempe.blueboxinc.net comp.lang.java.programmer:10136 On Sunday, November 20, 2011 1:11:00 PM UTC-8, sara wrote: > Here is the code: >=20 > ArrayList tmp=3Dnew ArrayList(); *DO NOT USE TAB CHARACTERS TO INDENT USENET CODE LISTINGS!* > tmp.add(-1); > tmp.add(-1); > System.out.println(DiGraph.GetBytes(tmp).length); > tmp.set(0, 10); > System.out.println(DiGraph.GetBytes(tmp).length); >=20 >=20 > public static byte[] GetBytes(Object v) { > ByteArrayOutputStream bos =3D new ByteArrayOutputStream(); > ObjectOutputStream oos; > try { > oos =3D new ObjectOutputStream(bos); > oos.writeObject(v); > oos.flush(); > oos.close(); > bos.close(); > } catch (IOException e) { > e.printStackTrace(); > } > byte[] data =3D bos.toByteArray(); > return data; > } >=20 > The problem is I need to write multiple arraylists on disk and later The problem is that the code you posted won't compile. > on I update the elements of them. I store the starting location of > arraylists and their size such that later I can refer to them. If the > size of objects change then it messes up! Could you please help? Java changes the sizes of things in surprising ways, and makes no promises = about the size of an 'ArrayList' in the way you're asking. What do you really want to do? > On Nov 20, 1:05=A0pm, markspace <-@.> wrote: *DO NOT TOP-POST!* --=20 Lew