Example
package com.pretech;import java.util.*;public class StringtoListExample {public static void main(String[] args) {System.out.println(getCommaSeparatedStringAsList("Welcome,to,pretech,blog"));}public static List getCommaSeparatedStringAsList(String commaSeparatedString) {List result = new ArrayList();if ((commaSeparatedString != null)&& (commaSeparatedString.length() > 0)) {StringTokenizer tokenizer = new StringTokenizer(commaSeparatedString, ",");while (tokenizer.hasMoreTokens()) {result.add(tokenizer.nextToken().trim());}}return result;}}
Output
[Welcome, to, pretech, blog]
No comments:
Post a Comment