I am parsing a grid coordinate in degree decimal format. I'd like to store pattern matches in a StringBuilder array for further manipulation. However, I am get a null pointer when calling append() in each while loop.
String coordinateExample = "N14585928W084144340";
this.parseCoordinate(coordinateExample);
...
public void parseCoordinate(String coordinateString) {
int i = 0;
//extract NSEW leading characters
Pattern pL = Pattern.compile("[A-Z]");
Matcher m = pL.matcher(coordinateString);
StringBuilder[] hemisphere = new StringBuilder[]{};
while (m.find()) {
hemisphere[i].append(m.group());
//System.out.println("m.group(): " + m.group());
i++;
}
// reset i
i = 0;
//extract decimal degree digits
Pattern pN = Pattern.compile("[0-9]++");
Matcher n = pN.matcher(coordinateString);
StringBuilder[] coordinate = new StringBuilder[]{};
while (n.find()) {
coordinate[i].append(n.group());
//System.out.println("q.group(): " + n.group());
i++;
}
}