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
Post a Comment