Here you can find the source of stringToList(String keywords, String delimiter)
public static List<String> stringToList(String keywords, String delimiter)
//package com.java2s; /* (c) 2014 Open Source Geospatial Foundation - all rights reserved * (c) 2001 - 2013 OpenPlans/*from w w w . java2s . c o m*/ * This code is licensed under the GPL 2.0 license, available at the root * application directory. */ import java.util.ArrayList; import java.util.Collections; import java.util.List; public class Main { public static List<String> stringToList(String keywords, String delimiter) { //// // // In the following cases we return an empty string: // - empty or null keyword // - empty or null delimiter // -delimiter not found at all // ///// if (keywords == null || keywords.length() == 0 || delimiter == null || delimiter.length() == 0 | keywords.indexOf(delimiter) < 0) return Collections.emptyList(); //// // // We know that the delimiter is used at least once, let's spli this string and create the corresponding list. // ///// final List<String> elements = new ArrayList<String>(); int index = -1; while ((index = keywords.indexOf(delimiter)) >= 0) { if (index > 0) elements.add(keywords.substring(0, index)); keywords = keywords.substring(index); } if (keywords.length() > 0) elements.add(keywords); return elements; } }