Search code examples
androidperformanceandroid-wificomparable

Most efficient way of making android.net.wifi.ScanResult a Comparable?


I want to sort android wifi ScanResult objects by BSSID levels. What would be the most efficient way to do that? Do I have to create my own Comparable ScanResult and write code to convert to/from ScanResult?


Solution

  • Creating your own Comparator will probably be more straightforward. Assuming you have some sort of Collection containing the ScanResults (list in the example below):

    Collections.sort(list, new Comparator<ScanResult>() {
        @Override public int compare(ScanResult lhs, ScanResult rhs) {
            // add your sorting logic
        } 
    });