I'm trying to code a realtime drawing App like the sample one Google has
https://github.com/googlearchive/AndroidDrawing
but I am curious to why they chose Arraylist<Point> data structure for adding points to the screen when drawing on the canvas. (It's adding about 100 Point objects when I draw a line )
Arraylist<Point>
https://github.com/googlearchive/AndroidDrawing/blob/master/app/src/main/java/com/firebase/drawing/Segment.java
The list of points represent one line.
Since an ArrayList is an implementation of a dynamic array. You have to constantly add new entries (points in this case) to the back of the container. Dynamic arrays have to be reallocated every time you change their size which means the entire contents have to be copied to a new block of memory. Linked lists, on the other hand, allow you to insert or remove entries without having to reallocate the rest of the list. Linked lists are much faster than dynamic arrays when you do frequent modification of the elements like you're doing here.
Why not use a LinkedList?
2.1m questions
2.1m answers
60 comments
57.0k users