fork download
  1. import java.util.*;
  2. import java.io.*;
  3.  
  4. class Ideone
  5. {
  6. public static void main(String[] args) {
  7. String text = "texttext(text)text(subtext), othertext152(de)sert(subothertext), textwithoutbracket, elems(subelem)";
  8. String[] parts = text.split(", ");
  9. String[][] result = new String[parts.length][2];
  10. for (int i = 0; i < parts.length; i++) {
  11. String part = parts[i];
  12. int lastIdx = part.lastIndexOf('(');
  13. if (lastIdx == -1) {
  14. result[i][0] = part;
  15. } else {
  16. result[i] = new String[] { part.substring(0, lastIdx), part.substring(lastIdx + 1, part.length() - 1) };
  17. }
  18. }
  19. Arrays.stream(result).forEach(arr -> System.out.println(Arrays.toString(arr)));
  20. }
  21. }
Success #stdin #stdout 0.08s 34096KB
stdin
Standard input is empty
stdout
[texttext(text)text, subtext]
[othertext152(de)sert, subothertext]
[textwithoutbracket, null]
[elems, subelem]