Search code examples
androidarraysibeacon-android

Store the scanned value in array and find the largest value in Android


In my Beacon application I am getting different values of RSSI through beacon.getRSSI(). Now I want to get the max value of RSSI of all the scanned beacons. So I thought the possible solution will be array. Can anyone helpout how to do this?


Solution

  • Put all the Beacon objects into a Collection (List, Set), then use Collections.max to get the beacon with the highest RSSI. javadoc

    List<Beacon> beacons = new ArrayList<Beacon>();
    // add all the beacons
    beacons.add(beacon);
    
    (...)
    
    Beacon maxBeacon = Collections.max(beacons, new Comparator<Beacon>(){
        public int compare(Beacon b1, Beacon b2) {
            return Integer.compare(b1.getRSSI(), b2.getRSSI);
        }
    }