By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
454,640 Members | 1,510 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 454,640 IT Pros & Developers. It's quick & easy.

circular list?

P: 27
Hello!
I have a private arraylist with classes that include two longs, a float and a BigDecimal. As new data comes in I currently am removing the oldest element, shifiting all other elements over, and then adding the newest element. I think this is taking up a lot of memory uncessearly. So is there anyway to make this a circle, so I don't need to shift over elements in the array? Thank you in advance for any help on this!
I'll include the relevenat parts of my code below:




Expand|Select|Wrap|Line Numbers
  1. private ArrayList<privStat> MyList = new ArrayList<privStat>();
  2. public class privStat {
  3.    long Stat1;
  4.    long Stat2;
  5.    float Stat3;
  6.    BigDecimal Stat4;
  7. }
  8.  
  9. NewStat = new privStat(//new message)
  10. if (MyList.size() - 1 < 10) {
  11.    MyList.add(NewStat);
  12. } else {
  13.     Mylist.remove(0);
  14.     Mylist.add(NewStat);
  15. }
  16.  
Mar 6 '12 #1
Share this Question
Share on Google+
1 Reply


P: 27
Any help on this Linked list??




Expand|Select|Wrap|Line Numbers
  1. private LinkedList<privStat> MyList = new LinkedList<privStat>();
  2. public class privStat {
  3.    long Stat1;
  4.    long Stat2;
  5.    float Stat3;
  6.    BigDecimal Stat4;
  7. }
  8.  
  9. NewStat = new privStat(//new message)
  10. if (MyList.size() - 1 < 10) {
  11.    MyList.add(NewStat);
  12. } else {
  13.     Mylist.remove(0);
  14.     Mylist.add(NewStat);
  15. }
  16.  
Mar 6 '12 #2

Post your reply

Sign in to post your reply or Sign up for a free account.