Java String Split by Word splitUnit(String word)

Here you can find the source of splitUnit(String word)

Description

split Unit

License

Open Source License

Declaration

public static String[] splitUnit(String word) 

Method Source Code


//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()]);
    }
}

Related

  1. split(String words, String character)
  2. splitIdentifierToWords(String str)
  3. splitIntoWords(String s)
  4. splitKeyWords(String sql)
  5. splitOne(String wordString)
  6. splitWord(List words, int listIndex)
  7. splitWords(String name)
  8. splitwords(String s)
  9. splitwords(String text)