Convert string to list, every char of string would be convert to string and added to list - Android java.lang

Android examples for java.lang:String Split

Description

Convert string to list, every char of string would be convert to string and added to list

Demo Code

import java.io.UnsupportedEncodingException;
import java.util.*;

public class Main{

    /**// ww  w  .j a  va 2  s .  c o m
     * Convert string to list, every char of string would be convert to string and added to list
     *
     * @param source string to be converted
     * @return <code>List</code>
     */
    public static List<String> string2List(String source) {
        if (source != null && source.length() > 0) {
            List<String> result = new ArrayList<String>();
            for (int i = 0; i < source.length(); i++) {
                result.add(String.valueOf(source.charAt(i)));
            }

            return result;
        } else {
            return null;
        }
    }

}

Related Tutorials