Here you can find the source of splitUnit(String word)
public static String[] splitUnit(String word)
//package com.java2s; //License from project: Open Source License import java.util.ArrayList; import java.util.List; public class Main { public static String[] splitUnit(String word) { List<String> list = new ArrayList<>(); int startIndex = 0, count = 0; for (int i = 0; i < word.length(); i++) { if (word.charAt(i) == '[') { if (count == 0) { startIndex = i;//from w ww . j av a2s .co m } count++; continue; } if (word.charAt(i) == ']') { count--; } if (count == 0) { list.add(word.substring(startIndex, i + 1)); } continue; } return list.toArray(new String[list.size()]); } }