Dynamic Array in Java
Is it possible to have dynamic arrays in Java?
How can I replicate .push() , splice() functions?
Use ArrayList. It’s by far the fastest implementation of List for Java. (Vector is only for thread safe and legacy uses, and requires more overhead)
List mylist = new ArrayList();
Most of the utility functions you’re looking for will be with the list or in the Collections utility class. (E.g. Collections.sort(mylist))
I highly, highly recommend spending a little time with the collections tutorial; it’ll make a worthwhile difference.
`ArrayList` is the fastest `List` implementation for access to individual elements (retrieval or update) – constant-time access – but the worst for resizing (order(N)). `LinkedList` is fastest for adding to or removing from either end, but order(N) performance for access.
To add to what Nick said, the capacity and size of a List are different things, so you can make the capacity larger than the size to reduce resizing. If you use ArrayList, you want to be aware of this because its default size is 10, IIRC!
Linked list is bad for random access, but does fine with iteration. (Comparable to ArrayList)
All of this depends on your use. I’d also read up on implementing Comparator and how that works with sorted sets/maps. The other key thing to understand is hashcode() and equals() and how they function in collections.
Thanks fellas, plenty to get stuck in to.
Is there any mention of this in Max’s java documentation?
These are general Java issues, not specifically Max ones.
Here’s a trail for the Collections machinery: