java - Most efficient way of creating a List for an Android App -


as of in title, experimenting 2 different ways of creating arraylistview in android.

the first 1 looks this:

list.add(new obj("smth", "note: na, na, na", image[0])); list.add(new obj("smth", "note: na, na, na", image[1])); list.add(new obj("smth", "note: na, na, na", image[2])); 

and has support array images:

private int[] images = {         r.drawable.image1,         r.drawable.image2,         r.drawable.image3,         ...} 

the other way uses getter , setter methods of obj.class. this:

arraylist<obj> objects = new arraylist<>();      obj a=new obj();     a.setname("smth");     a.setnote("na,na,na");     a.setimage(r.drawable.image1);     objects.add(a);      a=new obj();     a.setname("smth");     a.setnote("na, na, na");     a.setimage(r.drawable.image2);     objects.add(a);      a=new obj();     a.setname("smth");     a.setnote("na,na,na");     a.setimage(r.drawable.image3);     objects.add(a); 

is 1 of them better other? maybe increases performance in way? if list crowded hundreds of objects?

update: have tried run app many objects in list , performance seems better using second method. i'm sure there better ones!

your second approach better in terms of memory use. condense code following. give same performance lesser amount of code/ increase bit of performance because not calling many setters this.

arraylist<obj> objects = new arraylist<>();  obj a=new obj("smth", "note: na, na, na", r.drawable.image1); objects.add(a); a=new obj("smth", "note: na, na, na", r.drawable.image2); objects.add(a); a=new obj("smth", "note: na, na, na", r.drawable.image3); objects.add(a); 

and if have pattern values put in constructor, consider looping on , going reassigning , adding.


Comments

Popular posts from this blog

java - Static nested class instance -

c# - Bluetooth LE CanUpdate Characteristic property -

JavaScript - Replace variable from string in all occurrences -