by @kodeazy

flutter How to get second largest number in array of elements?

Home » flutter » flutter How to get second largest number in array of elements?
  • using sort function we can get the second smallest element in array
  • first we sort the array later get the last to second element.
  • Below is the sampl example

    import 'package:flutter/material.dart';
    void main() {
    print("hello");
    var example_array = [9, 8, 7, 6, 5, 4, 3, 2, 1];
    example_array.sort();
    print(example_array[example_array.length - 2]);
    }

    Output:

    8