Wrong array size when spliting an string

Try this. This will first split on the parens and then split on the second array element which has the coordinates sans, parens. The second split will split on any number of spaces followed by a command followed by any number of spaces.


String[] coord=coordenates.split("[()]")[1].split("\\s*,\\s*");
System.out.println(coord.length);
System.out.println(Arrays.toString(coord));

Prints

2
[37.3886303, -5.9953403]

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top