I want to get first longest string ? How can i do this ?
List<String> list = ['hi', 'hello', 'frozen', 'big mistake', 'cool daddy'];
I want to get first longest string ? How can i do this ?
List<String> list = ['hi', 'hello', 'frozen', 'big mistake', 'cool daddy'];
4
Answers
Check the below function i have done in my project to get the longest string.
And you can call the function like below to get the longest string
this is the shortest solution, which will return the longest string:
another alternative is:
The solution posted by Sparko Sol could also be used in an extension on
List<String>
to make it easier to reuse this method anywhere in the codebase. Such an extension could look something likeThen, to use this extension, you could simply write something like