How to find the longest string in an array of strings with Scala

1 Answer

0 votes
import scala.math.Ordering

object Main extends App {
  val arr = Array("scala", "functional", "programming", "object", "oriented")

  val longestString = arr.maxBy(_.length)

  println(longestString)
}

 
 
/*
run:
   
programming
 
*/

 



answered Dec 18, 2024 by avibootz
...