0

How do I convert String data ="[{1,1},{0,0}]" to double [][] data = new double[][]{{1,1},{0,0}}

in java

Martin G
  • 14,280
  • 9
  • 69
  • 82
sky
  • 25
  • 5
  • possible duplicate of [Java string to double conversion](http://stackoverflow.com/questions/2950529/java-string-to-double-conversion) – avalancha Feb 25 '15 at 16:23
  • Would that be some json input? If you are always going to get 4 doubles with the same set of parenthesis and separators, may a regexp be a quick solution? – dotvav Feb 25 '15 at 16:27
  • @dotvav ... it can vary, but the format is always same... this is coming from HTTP get method – sky Feb 25 '15 at 16:32

1 Answers1

1

If you need a flexible solution, a java.util.StringTokenizer should do it:

StringTokenizer scanner = new StringTokenizer(data, "[]{},", true);

You can parse a variable number of double tuples and also the tuple size is flexible (even different sizes are possible).

CoronA
  • 6,648
  • 2
  • 23
  • 47