Java performance and memory: LinkedList & arrays -


i'm building android app (so machines limited resources) , want know how picky should linkedlists.

i know arrays lightest containers , best @ random access, they're ideal choice if consider performance. however, rigidness pain when don't know how big list be.

so here's question: worth systematically use following type of mechanism in classes have 1 or more list of unpredictable size:

public class unpredictable public object[]realarray; private linkedlist<object> temp;  //what using classes call add items public void add(object item)  {     temp.add( item ); }  //what outer class calls when knows there's nothing left add  public void doneadding()  {     realarray = new object[tmp.size()];     transferandrecycle(); }  private void transferandrecycle() {     // copy items linkedlist array } 

so guess i'm asking if it's worth take steps rid of space java's linkedlist object takes?

any input? thanks

i think providing lot of services arraylist class contains. arraylist gives o(1) element access; linked list it's o(n). underlying mechanism of arraylist array. can control size of array manipulating capacity.

look closely @ arraylist -- may avoid reinventing wheels.

additional thought: arrays , generics don't play nicely. arraylists do. small item important you.


Comments

Popular posts from this blog

c++ - Is it possible to compile a VST on linux? -

java - Output of Eclipse is rubbish -

jquery - Confused with JSON data and normal data in Django ajax request -