Possible Duplicate:
Java: How to convert comma separated String to ArrayList
I have a the String Red*Blue*Yellow*Green*White. How do I break that String out by * into a List<String>?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
You can try this: –
NOTE:-
Arrays.asListreturns you anunmodifiablelist, so if you want amodifiable list, you need to create a new list by using theconstructor of ArrayList, that takes aCollectionobject as parameter.Also, since
*is a special character inRegex, andString.split()takes aRegexfor splitting. So, you need to escape the*with a backslash.OUTPUT: –