title: Scala how to split string and store into array?
body: <p>I am currently writing a program that read a string like "2 + 2". It should be split regarding the spaces and store into an Array like Array(2, +, 2). However, I am not sure how to do it within a method (since I usually work in Scala interpreter), access to the result after I split it. I know that in java, you can do String[] arr = string.split("\s+"). </p>
  
  <pre><code>def eval(s: String): Double = {
  var result = 0;
  s.split("\\s+");
  //how do i retrieve the element that was split?
  // I am trying to retrieve, like the above example, the 2 and 2
  // perform an addition on them so the method will return a double
  result;
  }      
  </code></pre>