- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to convert a comma separated String into an ArrayList in Java?
To convert a comma separated String into an ArrayList
- Split the String into an array of Strings using the split() method.
- Now, convert the obtained String array to list using the asList() method of the Arrays class.
Example
import java.util.Arrays; import java.util.List; public class Sample { public static void main(String[] args) { String myString = "JavaFx,Java,WebGL,OpenCV"; String[] myArray = myString.split(","); System.out.println("Contents of the array ::"+Arrays.toString(myArray)); List <String> myList = Arrays.asList(myArray); } }
Output
Contents of the array ::[JavaFx, Java, WebGL, OpenCV]
Advertisements