title: Read values from formatted string Java, Groovy
body: <p>I'm wondering if there is any nice way how to read single attributes from formatted string in Groovy or even in Java.</p>
  
  <p>I have a string containing some attributes separated by space. For example "2.1 20 Something true". The order is fixed and the "attribute type" is known (for the example first is Float, second is Integer, etc.). I need something similar to String.format() but other way round.</p>
  
  <p>I know that I can split the string manually and read the values, but this makes the code too complicated like this:</p>
  
  <pre><code>String[] parsedText = "2.1 20 Something true".split(delimiter)
  
  try {
     firstVal = new Float(parsedText[0])
  }
  catch (NumberFormatException e) {
     throw new RuntimeException("Bad data [0th position in data string], cannot read[{$parsedData[0]}], cannot convert to float")
  }
  ...
  </code></pre>
  
  <p>Is there a better way? I'm pretty sure that at least in Groovy is:-)</p>
  
  <p>Thanks!</p>