Inserting a value into an IntList

edited October 2013 in Programming Questions

Okay, I've been using ArrayLists to collect objects and that works great for me. The feature I really like is the add() function where I can insert an object at a specific index and the ArrayList shifts all of the other objects after the new object down one. And you can do cool things like swap() with ArrayLists using Collections. Is there a nice way to shift values with IntLists?

I've created a way by appending to the end of the IntList, shifting each int down, one by one, then use the set() to place the new int into the middle of the list, or whereever. Not very neat, nor efficient.

Would I be better off creating object classes which store an int value and then storing those in ArrayLists? That doesn't seem very good either. At some point I will be figuring out Tables and attempting to store the values in them. The Tables will either import the values from the IntLists or I'll just store the values directly in the Tables. Tables will mainly be for exporting/imports CSV files, but if they can be managed easily enough, I will use them for dynamic storing of values.

Any ideas?

Answers

  • edited October 2013

    Now that I've taken the time to look at it, I've found a possible answer here: processing.org/reference/javadoc/core/ with the insert() function for IntLists. I will try that.

  • edited October 2013

    Actually, after looking at the Table class I should just go with building Tables for my data. I need to anyway and all the functionality is there for inserting rows. If someone wants to weight in on IntLists or Tables, please do. Or just post, "Yeah, do that." and I can mark this question as answered. It seems I can't mark my own comments as an answer.

  • Answer ✓

    An ArrayList is appropriate to store your own classes.
    And Table is a ready-made general structure for CSV and such. O:-)

Sign In or Register to comment.