The Artima Developer Community
Sponsored Link

Java Answers Forum
How to "recycle" an ArrayList?

2 replies on 1 page. Most recent reply: Aug 28, 2003 4:44 AM by Dor

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 2 replies on 1 page
Dor

Posts: 13
Nickname: eis
Registered: Jul, 2003

How to "recycle" an ArrayList? Posted: Aug 28, 2003 4:16 AM
Reply to this message Reply
Advertisement
Hi everyone!

I am using one ArrayList called "releAttr" in my program. Since I'd like to use it for several times for different groups of objects, I need one clean way to 'recycle' it, i.e. getting the container totally empty again.

I tried the removeRange(int fromIndex, int toIndex) method, but it was a protected one. And now the only choice I am left with is to run a loop with method remove(int index). I was also wondering if I could go straight and declare "releAttr=null", but I guess in that way I wouldn't be able to release all the memory correctly(or could I?).

Could you please help me with that?


Senthoorkumaran Punniamoorthy

Posts: 335
Nickname: senthoor
Registered: Mar, 2002

Re: How to "recycle" an ArrayList? Posted: Aug 28, 2003 4:38 AM
Reply to this message Reply
Why not?? setting releAttr to null (releAttr=null) should release the memory of the array list. Don't use the for loop to remove the entries.

When you want to use it again do this
releAttr = new ArrayList()


or just the better way would be is whenever you want to use the ArrayList without doing this
releAttr = null;
releAttr = new ArrayList();


you could simply do this I guess
releAttr = new ArrayList()

Dor

Posts: 13
Nickname: eis
Registered: Jul, 2003

Re: How to "recycle" an ArrayList? Posted: Aug 28, 2003 4:44 AM
Reply to this message Reply
Thanks, Senthoor!

Flat View: This topic has 2 replies on 1 page
Topic: please please help - palindrome program Previous Topic   Next Topic Topic: Java inputstream reader

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use