How to split a string at the first occurrence of a separator in Scala

1 Answer

0 votes
object Program {
  def main(args: Array[String]): Unit = {
    val str = "scala java, go c, c++ python, c#"
    
    val parts = str.split(",", 2)  // Limit to 2 splits
    
    println(parts(0))
    println(parts(1))
  }
}


    
    
/*
run:
    
scala java
 go c, c++ python, c#
    
*/

 



answered Aug 26, 2024 by avibootz

Related questions

...