java - What would be the best way of converting Object ArrayList to Double List -


i've started learn java/android , trying gather rssi values of bluetooth devices. have 2 fragments on same activity , every device discover show on listview , keep collecting data in arraylist holds object class. later when want visualize data device, need convert object array list arraylist rssi values , show on second fragment. problem conversion made screens slow. suggestions? thank you

this function , think makes slow;

public static arraylist<double> extractdevicerssionly(objdevice device,         arraylist<objdevice> list) {     arraylist<double> selectedlist=new arraylist<double>();     if(device!=null&& list!=null) {         if (list.size() > 0) {             for(int i=0;i<list.size();i++)             {                 if(list.get(i).get_macaddress().equals(device.get_macaddress())) {                     selectedlist.add(list.get(i).get_signalstrength());                 }             }         }         return selectedlist;     } } 

your code looks good. can make tiny bit more efficient avoiding calling get(i) twice. enhanced for that, , give cleaner code.

as suggested @makoto, can avoid list.size() > 0 test too. empty list not iterate.

if (device != null && list != null) {     (objdevice objdevice : list) {         if (objdevice.get_macaddress().equals(device.get_macaddress())) {             selectedlist.add(objdevice.get_signalstrength());         }     } } 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -