String inputLine = "Adams, John Quincy";
// Construct an RE with parens to "grab" both field1 and field2
Pattern r = Pattern.compile("(.*), (.*)");
Matcher m = r.matcher(inputLine);
if (!m.matches())
throw new IllegalArgumentException("Bad input");
System.out.println(m.group(2) + ' " + m.group(1));