Java String to List toList(String list)

Here you can find the source of toList(String list)

Description

to List

License

Open Source License

Declaration

public static ArrayList toList(String list) 

Method Source Code

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

import java.util.ArrayList;

public class Main {
    public static ArrayList toList(String list) {
        // TODO Auto-generated method stub
        ArrayList l = new ArrayList();
        String aux;//from   www . ja v a2  s .  c o m
        aux = list;
        while (aux.indexOf(',') > 0) {
            l.add(aux.substring(0, aux.indexOf(',')).trim());
            aux = aux.substring(aux.indexOf(',') + 1);
        }
        if (aux.trim().compareTo("") != 0) {
            l.add(aux.trim());
        }
        return l;
    }

    public static ArrayList toList(String[] list) {
        // TODO Auto-generated method stub
        ArrayList l = new ArrayList();

        for (int i = 0; i < list.length; i++) {
            l.add(list[i]);
        }

        return l;
    }

    public static ArrayList toList(String list, String sep) {
        // TODO Auto-generated method stub
        ArrayList l = new ArrayList();
        String aux;
        aux = list;
        while (aux.indexOf(sep) > 0) {
            l.add(aux.substring(0, aux.indexOf(sep)).trim());
            aux = aux.substring(aux.indexOf(sep) + 1);
        }
        if (aux.trim().compareTo("") != 0) {
            l.add(aux.trim());
        }
        return l;
    }
}

Related

  1. strToAList(String strTokenize)
  2. strToList(String str, String regex)
  3. strToList(String str, String separator)
  4. strToList(String str, String split)
  5. strToList(String value)
  6. toList(String s)
  7. toList(String s, String delim)
  8. toList(String s, String delimiter)
  9. toList(String str)