Your input is a series of pairs of numbers, so here's how to get an array double[][2]
.
public static void main(String[] args) {
final String data = "(("
+ "39.4189453125 37.418708616699824,"
+ "42.0556640625 37.418708616699824,"
+ "43.4619140625 34.79181436843146,"
+ "38.84765625 33.84817790215085,"
+ "39.4189453125 37.418708616699824"
+ "))";
final Pattern topLevelPattern = Pattern.compile("\\(\\((.*)\\)\\)");
final Pattern pairSeparator = Pattern.compile(",");
Matcher topLevelMatcher = topLevelPattern.matcher(data);
if (!topLevelMatcher.matches())
throw new IllegalArgumentException("Data not surrounded by double parentheses");
String topLevelData = topLevelMatcher.group(1);
double[][] pairsArray = pairSeparator.splitAsStream(topLevelData)
.map(s -> s.split("\\s+"))
.map(a -> new double[]{Double.parseDouble(a[0]), Double.parseDouble(a[1])})
.toArray(double[][]::new);
for (double[] pair : pairsArray)
System.out.println(Arrays.toString(pair));
}
source
share