Java String Extract extractItems(String items)

Here you can find the source of extractItems(String items)

Description

splits a string of type {("A","B","C")} into ["A", "B", "C"]

License

Open Source License

Declaration

public static List<String> extractItems(String items) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.util.ArrayList;

import java.util.List;

public class Main {
    /**/*from  w  w  w.  ja  v  a2s  .co  m*/
     * splits a string of type {("A","B<C,D>","C")} into ["A", "B<C,D>", "C"]
     * */
    public static List<String> extractItems(String items) {
        List<String> itemList = new ArrayList<String>();
        if (items == null)
            return itemList;
        items = items.replace(" ", ""); //remove all spaces      
        if (items.split("\"(.)*\"").length == 1)
            return itemList;
        String[] arrayItems = items.split("\",");

        for (int i = 0; i < arrayItems.length; i++) {
            //there is exactly one " in each arrayItem[i], and we need the string from the right of it
            String[] rightStr = arrayItems[i].split("\"");
            if (rightStr.length > 0)
                itemList.add(rightStr[1]);
        }
        return itemList;
    }
}

Related

  1. extractCommands(String fileContents)
  2. extractData(String message)
  3. extractField(int position, String regex, String source)
  4. extractGenericTypeNames(String sig)
  5. extractHorizontalTabs(String line, int tabSize)
  6. extractJobId(String line)
  7. extractKeyCodes(String codes)
  8. extractLines(String data, int tabWidth)
  9. extractNoPublicDomains(String domains)